Wednesday, September 16, 2015

Schedule FiOS Router Reboots with a Pogoplug

There are few things in life more irritating than having your Internet go out. This is often caused by your router needing a reboot. Sadly, not all routers are created equal which complicates things a bit. At my home for example, we have FIOS Internet. My connection from my ONT to my FIOS router is through coaxial (coax cable). Why does this matter? Because if I was connected to CAT6 from my ONT, I could use the router of my choosing. Sadly a coaxial connection doesn’t easily afford me this opportunity.
So why don’t I just switch my FIOS over to CAT6 instead of using the coaxial cable? Because I have no interest in running the CAT6 throughout my home. This means I must get the most out of my ISP provided router as possible.
What is so awful about using the Actiontec router?
1) The Actiontec router overheats when using wifi and router duties.
2) This router has a small NAT table that means frequent rebooting is needed.
Thankfully, I’m pretty good at coming up with reliable solutions. To tackle the first issue, I simply turned off the wifi portion of the Actiontec router. This allowed me to connect to my own personal WiFi instead. As for the second problem, this was a bit trickier. Having tested the “Internet Only Bridge” approach for the Actiontec and watching it fail often, I finally settled on using my own personal router as a switch instead. It turned out to be far more reliable and I wasn’t having to mess with it every time my ISP renewed a new IP address. Trust me when I say I’m well aware of ALL of the options and this is what works best for me. Okay, moving on.
Automatic rebooting
As reliable as my current setup is, there is still the issue of the small NAT table with the Actiontec. Being the sort of person who likes simple, I usually just reboot the router when things start slowing down. It’s rarely needed, however getting to the box is a pain in the butt.
This lead me on a mission: how can I automatically reboot my router without buying any extra hardware? I’m on a budget, so simply buying one of those IP-enabled remote power switches wasn’t something I was going to do. After all, if the thing stops working, I’m left with a useless brick.
Instead, I decided to build my own. Looking around in my “crap box”, I discovered two Pogoplugs I had forgotten about. These devices provide photo backup and sharing for the less tech savvy among us. All I need to do was install Linux onto the Pogoplug device.
Why would someone choose a Pogoplug vs a Rasberry Pi? Easy, the Pogoplugs are “stupid cheap.” According to the current listings on Amazon, a Pi Model B+ is $32 and a Pi 2 will run $41 USD. Compare that to $10 for a new Pogoplug and it’s obvious which option makes the most sense. I’d much rather free up my Pi for other duties than merely managing my router’s ability to reboot itself.

Installing Debian onto the Pogoplug

I should point out that most of the tutorials regarding installing Debian (or any Linux distro) onto a Pogoplug are missing information, half-wrong and almost certain to brick the device. After extensive research I found a tutorial that provides complete, accurate information. Based on that research, I recommend using the tutorial for the Pogoplug v4 (both Series 4 and Mobile). If you try out the linked tutorial on other Pogoplug models you will “brick” the Pogoplug.
Getting started: When running the curl command (for dropbear), if you are getting errors – leave the box plugged in and Ethernet connected for at least an hour. If you continue to see the error: “pogoplug curl: (7) Failed to connect to”, then you need to contact Pogoplug to have them de-register the device.
Pogoplug Support Email
Pogoplug Support Email
If installing Debian on the Pogoplug sounds scary or you’ve already got a Raspberry Pi running Linux that you’re not using, then you’re ready for the next step.
Setting up your router reboot box
(Hat tip to Verizon Forums)
Important: After you’ve installed Debian onto your Pogoplug v4 (or setup your existing Rasberry Pi instead), you would be wise to consider setting up a common non-root user for casual SSH sessions. Even though this is behind your router’s firewall, you’re still running a Linux box as root with various open ports.
First up, login to your Actiontec MI424WR (or similar) FIOS router, browse to Advanced, click Yes to acknowledge the warning, then click on Local Administration on the bottom left. Check “Using Primary Telnet Port (23)” and hit Apply. This is for local administration only and is not to be confused with Remote Administration settings.
Go ahead and SSH into your newly tweaked Pogoplug. Next, you’re going to want to install a package called “expect.” Assuming you’re not running as root, we’ll be using “sudo” for this demonstration. I first discovered this concept on the Verizon forums last year. Even though it was scripted for a Pi, I found it also works great on the Pogoplug. SSH into your Pogoplug:
  1. cd /home/non-root-username/
  1. sudo apt-get install expect -y
Next, run nano in a terminal and paste in the following contents, edit any mention of your /home/non-root-username/ and your router’s IP LAN address to match your personal details.
  1. spawn telnet
  2. expect "Username:"
  3. send "admin\r"
  4. expect "Password:"
  5. send "ACTUAL-ROUTER-password\r"
  6. expect "Wireless Broadband Router> "
  7. sleep 5
  8. send "system reboot\r"
  9. sleep 5
  10. send "exit\r"
  11. close
  12. sleep 5
  13. exit
Now name the file verizonrouterreboot.expect and save it. You’ll note that we’re saving this in your /home/non-root-username/ directory. You could call the file anything you like, but for the sake of consistency, I’m sticking with the file names as I have them.
The file we just created accesses the router via telnet (locally), then using hard returns (\r) is logging into the router and rebooting it. Clearly this file on it’s own would be annoying, since executing it just reboots your router. However it does provide the executable for our next file so that we can automate when we want it to run.
Let’s open nano in the same directory and paste in the following contents:
  1. {
  2. cd /home/non-root-username/
  3. expect -f verizonrouterreboot.expect
  4. echo "\r"
  5. } 2>&1 > /home/non-root-username/verizonrouterreboot.log
  6. echo "Nightly Reboot Successful: $(date)" >> /home/non-root-username/successful.log
  7. sleep 3
  8. exit
Now save this file as so it can provide you with a log file and run your expect script.
As an added bonus, I’m going to also provide you with a script that will reboot the router if the Internet goes out or the router isn’t connecting with your ISP.
Once again, open up nano in the same directory and drop the following into it:
  1. #!/bin/bash
  2. if ping -c 1
  3. then
  4. : # colon is a null and is required
  5. else
  6. /home/non-root-username/
  7. fi
Save this file as and it will make sure you’ll never have to go fishing for the power outlet ever again. This script is designed to ping an OpenDNS server on a set schedule (explained shortly). If the ping fails, it then runs the reboot script.
Before I wrap this up, there are two things that must still be done to make this work. First, we need to make sure these files can be executed.
  1. chmod +x /
  1. chmod +x verizonrouterreboot.expect
  1. chmod +x
Pogoplug Debian
Pogoplug Debian
Now that our scripts are executable, the next step is to schedule the scripts on their appropriate schedules. My recommendation is to schedule at a time when no one is using the computer, say at 4am. And I recommend running “pingme” every 30 minutes. After all, who wants to be without the Internet for more than 30 minutes? You can setup a cron job and then verify your schedule is set up correctly.
Are you a cable Internet user?
You are? That’s awesome! As luck would have it, I’m working on two different approaches for automatically rebooting cable modems. If you use a cable modem and would be interested in helping me test these techniques out, HIT THE COMMENTS and let’s put our heads together. Let me know if you’re willing to help me do some testing!
I need to be able to test both the “telnet method” and the “wget to url” method with your help. Ideally if both work, this will cover most cable modem types and reboot methods.

How to install Ioncube Loader on CentOS, Debian and Ubuntu

The Ioncube loader is a PHP module to load files that were protected with the Ioncube Encoder software. Ioncube is often used by commercial PHP software vendors to protect their software, so it is likely that you come across an Ioncube encoded file sooner or later when you install extensions for CMS or Shop software written in PHP. In this tutorial, I will explain the installation of the Ioncube loader module in detail for CentOS, Debian, and Ubuntu.

1 Prerequisites

Your server must have the PHP programming language installed. I will use the command line Editor Nano and the command line download application wget. Nano and Wget are installed on most servers, in case they are missing on your server then install them with apt / yum:


yum install nano wget

Debian and Ubuntu

apt-get install nano wget

2 Download Ioncube Loader

The Ioncube loader files can be downloaded free of charge from Ioncube Inc. They exist for 32Bit and 64Bit Linux systems.
In the first step, I will check if the server is a 32Bit or 64Bit system. Run:
uname -a
The output will be similar to this:
Run uname -a command.
When the text contains "x86_64" then the server runs a 64Bit Linux Kerbel, otherwise it's a 32Bit (i386) Kernel. Most current Linux servers run a 64Bit Kernel.
Download the Loader in tar.gz format to the /tmp folder and unpack it:
For 64Bit x86_64 Linux:
cd /tmp
tar xfz ioncube_loaders_lin_x86-64.tar.gz
For 32Bit i386 Linux:
cd /tmp
tar xfz ioncube_loaders_lin_x86.tar.gz
The files get unpacked into a folder with the name "ioncube".

3 Which Ioncube Loader is the right one?

When you run "ls /tmp/ioncube" then you see that there are many loader files in the ioncube directory.
List of ioncube loader files.
The files have a number that corresponds with the PHP version they are made for and there is also a "_ts" (Thread Safe) version of each loader. We will use the version without thread safety here.
To find out the installed php version, run the command:
php -v
The output will be similar to this:
The php -v output.
For this task only the first two digits of the version number in the first result line matter, on this server I'll run PHP 5.6. We note this number as we need it for the next steps.
Now it's time to find out where the extension directory of this PHP version is, run the following command to find the directory name:
php -i | grep extension_dir
The output should be similar to the one from this screenshot:
The PHP extension directory path.
I marked the path in the screenshot, the extension directory on this server is "/usr/lib/php5/20131226". The directory name will be different for each PHP version and Linux distribution, jus use the one you get from the command and not the one that I got here.
No well copy the ioncube loader for our PHP version 5.6 to the extension directory /usr/lib/php5/20131226:
cp /tmp/ioncube/ /usr/lib/php5/20131226/
Replace "5.6" in the above with your PHP version and "/usr/lib/php5/20131226" with the extension directory of your PHP version.

4 Configure PHP for the Ioncube Loader

The next configuration step is a bit different for Centos and Debian/Ubuntu. We will have to add a line:
zend_extension = /usr/lib/php5/20131226/
as first line into the php.ini file(s) of the system. Again, the above path contains the extension directory "/usr/lib/php5/20131226" and the PHP version "5.6", ensure that you replace them to match your system setup. I'll start with the instructions for CentOS.

3.1 Configure Ioncube loader on CentOS

Centos has just one central phhp.ini file where we have to add the ioncube loader to. Open the file /etc/php.ini with an editor:
nano /etc/php.ini
and add "zend_extension =" plus the path to the ioncube loader as the first line in the file.
zend_extension = /usr/lib/php5/20131226/
Then save the file and restart the apache web server:
service httpd restart
service php-fpm restart

3.1 Configure Ioncube loader on Debian and Ubuntu

Debian and Ubuntu use separate php.ini files for PHP CLI (Commandline), CGI, Apache2 and FPM mode. The file paths are:
  • /etc/php5/apache2/php.ini
  • /etc/php5/cli/php.ini
  • /etc/php5/cgi/php.ini
  • /etc/php5/fpm/php.ini
A file has to be edited to enable the ioncube loader into the corresponding PHP mode. You are free to leave out files for PHP modes that you don't use or where you don't need ioncube loader support. It is also possible that you don't have all files on your server, so don't worry when you can't find one of the files.
Apache mod_php
nano /etc/php5/apache2/php.ini
Command line PHP (CLI)
nano /etc/php5/cli/php.ini
PHP CGI (used for CGI and Fast_CGI modes)
nano /etc/php5/cgi/php.ini
nano /etc/php5/fpm/php.ini
and add "zend_extension =" plus the path to the ioncube loader as the first line in the file(s).
zend_extension = /usr/lib/php5/20131226/
Then save the file(s) and restart the apache webserver and php-fpm:
service apache2 restart
service php5-fpm restart

5 Test Ioncube

Let's check if ioncube loader has been installed successfully. First I will test the commandline PHP. Run:
php -v
Ioncube loaded in cli PHP.
I marked the line in white that shows that the ioncube loader has been enabled:
with the ionCube PHP Loader (enabled) + Intrusion Protection from (unconfigured) v5.0.17, Copyright (c) 2002-2015, by ionCube Ltd.
If you like to test the PHP of a website, create an "info.php file with this content:
And open the URL in a web browser. You will be able to see ioncube in the phpinfo() output:
PHP info output with ioncube module loaded.

How to extend GIMP with GMIC

GIMP is the n1 open source image editor and raster graphics manipulator that offers an array of special effects and filters out of the box. Although the software's default capabilities will be more than enough for most people out there, there isn't any reason why you couldn't expand them if you wished for it. While there are many ways to do exactly that, I will focus on how to enrich your GIMP filters and effects sets with the use of G'MIC.

Extend GIMP with G'MIC

G'MIC is an acronym for GREYC's Magic for Image Computing and it is basically an open-source image processing framework that can be used through the command line, online, or on GIMP in the form of an external plugin. As a plugin, it boasts over 400 additional filters and effects, so the expansion of GIMP's possibilities is significant and important.
First, thing you need to do is download the plugin from G'MIC's download web page. Note that the plugin is available in both 32 and 64-bit architectures and that it has to match your existing GIMP (and OS) installation to work. Download the proper G'MIC version and decompress the contents of the downloaded file under the /.gimp-2.8/plug-ins directory. This is a “hidden” directory so you'll have to press “Ctrl+H” when in your Home folder and then locate the folder.
Note that the G'MIC plugin is actually an executable that must be placed in the directory “/.gimp-2.8/plug-ins”. The directory structure is important as placing the G'MIC folder in the plug-ins won't change anything on GIMP.
After having done that, close your GIMP (if open) and restart it. If the plugin was installed correctly, you should be seeing a “G'MIC” entry in the “Filters” options menu. Pressing it will open up a new window that contains all of the new filters and effects.
Each filter features adjustable settings on the right size of the window, while a convenient preview screen is placed on the left. Users may also use specific layers to apply filters on, or even use their own G'MIC code as a new “custom filter”.
While many of the G'MIC filters are already available in GIMP, you will find a lot that aren't so dig deep and locate the one thing that you need every time. Luckily, G'MIC offers categorization for its multitudinous effects collection.

Install G'MIC on Ubuntu

If you're using Ubuntu derivatives, you can also install G'MIC through a third party repository. You can add it at your own risk by entering the following commands on a terminal:
sudo add-apt-repository ppa:otto-kesselgulasch/gimp
sudo apt-get update
sudo apt-get install gimp-gmic
The benefit from doing this is that you will get G'MIC updates whenever there are any, instead of having to download the latest version and to untar the file in the appropriate folder again.

Other GIMP Plugins

G'MIC is certainly great for when you're looking for a filtering extension, but here are some other GIMP plugins that will help you expand other aspects of this powerful software. The GIMP Paint Studio for example is great when in need for additional brushes and their accompanying tool presets, the GIMP Animation Package helps you create simple animations, and finally the FX-Foundry Scripts Pack is a selection of high-quality scripts that do wonders in many cases.