Saturday, June 20, 2015

Printing from Android Phones to Epson printers

The problem of printing from mobile devices is somewhat involved. The main problem is that standards like WiFi Direct or bluetooth printing are still in early stages of deployment. Some vendors have their own solutions that work pretty well with their devices, but they tend to be islands. Google has cloud print, but that requires a dedicated print server on the local network running headless Chrome to route the print jobs. I don't know the details of Apple Cloud Print, but it probably works in a similar way, with some local device acting as the print server.

On my Samsung Galaxy S6, I decided to download the Epson Print Enabler from the Play Store. Once it was installed and enabled, I took the phone to close proximity of my printer, and Epson WF-3520 multi-purpose wireless inkjet and tried to print a web page from Chrome. Chrome defaults to printing to a PDF document, but I was able to select the Epson from a drop down list, deselect the pages I did not want to print and send a single page of the web site to the printer. It worked like magic.

This is one of the island solutions that might only work with Android phones and Epson wireless printers, but it does work without any print server set up or routing through the Internet. The Epson printer is the best wireless inkjet I've owned and is highly recommended whether you want to use the Android printing features or not.

Saturday, June 6, 2015

Limiting connections to port 80

The Linux software firewall, iptables, has the ability to limit the number of concurrent connections on a specific port. This could be used as a crude DDOS defense. It won't save a web site, but it might save the server from becoming overwhelmed and unresponsive. Here is an example of limiting the number of connections on port 80 to 25. After 25 open connections, the next connection is dropped.

iptables -A INPUT -p tcp --syn --dport 80 -m connlimit --connlimit-above 25 -j REJECT --reject-with tcp-reset

Wednesday, March 25, 2015

Simple routing in Linux

The Linux kernel has pretty capable network routing capabilities.

To see the current routing table:
route -n

The default gateway will have the "UG" flags shown in the output. Red Hat and CentOS systems usually have the routing table stored in /etc/sysconfig/network-scripts/ by network device (e.g., route-eth1, route-eno1). To change or modify the routing table, you must be root.

To add a default gateway from the command line:
/sbin/route add default gw ip-address eth0

To add a static route, use the ip command and specify the destination and interface:
/sbin/ip route add 192.168.1.0/24 via 192.168.2.254 dev eno1

To see how packets will be routed to an ip address:
/sbin/ip route get ip-address

Saturday, January 3, 2015

Chromebook keyboard shortcuts

Last year, I replaced my Android tablet with an Acer i3 Chromebook. It was one of my best technology moves of the year. I love the form factor, keyboard, built-in SSH, screen, external ports, and ability to run a native Linux distro in paravirtual machine. The only thing I didn't like about the keyboard was that is was missing a DELETE key. The fix for that is a keyboard shortcut:
Alt+Backspace

Take a screenshot with Ctrl+[show windows].

The show windows button looks like a window with two vertical bars after it. Screenshots are saved to your Downloads directory with the date and time as PNG files.

Here are more keyboard shortcuts from OMG Chrome.

Wednesday, August 20, 2014

Ruby on Rails scaffold generated form fields

Rails has a cool feature that generates basic CRUD screens based on command line input. It can generate a model file, a set of views, a controller, tests, and migrations. While officially shunned for production code, scaffolding may produce most of the functionality you need in parts of your application.

It generates views with array style form field names. For example, if your model name is "widget" and it has an attribute of "column1", the form name generated in views will be name="widget[column1]". It may not be immediately clear how to reference this field using params in the controller.

The answer is to reference it as a hash of hashes. A simple name="field" is referenced in the controller as params[:field]. The scaffold generated field in the above example would be referenced as params[:widget][:column1].

Thursday, July 31, 2014

Chromebook, crouton, Ubuntu trusty

I had been in the market for a low cost Linux laptop for a while, but was not overly excited about the choices. There are a small number of Linux laptop vendors, and Dell offers an Ubuntu based ultrabook at a price around $1300. That is not a low cost option.

Then, I found a blog post where someone had installed Linux on a chromebook. I always thought chromebooks were interesting, but limited. The ability to run Linux in a paravirtual mode sold me, but I still had issues with the performance, having used a chromebook loner earlier this year. I was waiting for the new generation of chromebooks to be released late this summer with Intel i3 processors. That would be plenty of horsepower to run Linux and Chromium at a low cost.

I am typing this post on an Acer C720 with the i3 and 4GB RAM ($379), just a few days out of the box. So far, I am happy with the fit and finish of the Acer, the performance, the ports (2 USB, 1 SD, 1 HDMI, Wifi, Bluetooth), and battery life. Following this guide from Lifehacker, using a script from Google called crouton, I installed Ubuntu in a chroot environment and am able to hot key back and forth between Linux and Chromium. It is freaking sweet!

If you run a crouton install with no parameters, you get Ubuntu 12 which is a couple of years old. However, there are 3 versions of Debian, a penetration testing distro called Kali, and 2 versions of Ubuntu LTS available from crouton. After some experimentation, I eventually installed Ubuntu 14 LTS (trusty) with the Unity desktop using this command:

sudo sh -e ~/Downloads/crouton -r trusty -t unity

It doesn't come with a lot of applications, so I need to get busy with apt-get and set up my development environment. This is the low cost Linux machine I've been wanting.

Sunday, April 20, 2014

Blocking and unblocking an IP using iptables

Iptables is the Linux software firewall.

To block an IP (all ports), as root:

iptables -I INPUT -s ip-address -j DROP

To unblock an IP:

There are two steps. The iptables rule must be deleted by line number, so first you need to determine which rule you want to delete.
iptables -L -n --line-numbers

Next, delete the rule for the IP you want to unblock. This will delete rule number 3:
iptables -D INPUT 3

To clear all firewall rules, use the flush switch
iptables -F