Raspberry Pi Dumb Terminal And Then Some

As someone whose interest in computing struck in the early 1980s I've always loved small self-contained computers. In my teens I discovered dumb terminals. However, it wasn't until the last ten years when I found myself SSHing in to remote servers that the idea I might have a use for one made any sense.

I Googled, I pored over oldcomputers.com and terminals-wiki.org, I watched old films. I kept coming back to the DEC VT100. I scoured eBay and other sites but they rarely come up and when they do are out of my price range.

Picture of a VT100 terminal

It dawned on me, "heck! I have a 3D printer, a competency with CAD, Linux, and basic electronics, and oh, the Raspberry Pi would be perfect for this."

First things first was to source the parts so I could design my VT100 around it.

The guts would be a Raspberry Pi Zero W since all I intended to use it for would be connecting to other systems.

The screen was straightforward enough on AliExpress. A nice 8", 4:3 screen with driver board, HDMI, VGA, and AV inputs was only ~£26. It's bright and sharp and only requires 12v at 2-4amp.

8

With a big enough power supply I could power the Pi and the screen from one input. I bought a simple step-down board to convert 12v to 5v with a USB output.

12v to 5v converter

The keyboard was a bit of a headscratcher. I wasn't about to 3D print a chassis and full keyboard so I was forced to compromise on the VT100 authenticity. I bought a cheap small USB keyboard. A future upgrade might be to make a housing this 3rd party keyboard would fit in to.

I leapt in with both feet (and a set of calipers) and designed a small VT100 which would fit the screen I had nicely.

Screenshot of VT100 design

The further I got in to designing it I realized how difficult it would be to print on my printer (the case itself would require six or seven parts glued together) and that it would take up a lot of precious desk space. I decided version one should be a working machine, not a faithful reconstruction. With a coffee and a notebook I started with some sketches.

Sketches

With 3d printing in mind I selected one design and created it in CAD, but I found it wanting. Instead of a side-by-side arrangement for the circuit boards I came up with a design where the boards are stacked.

Abandoned design Abandoned design

Final design Final design

Circuit board arrangement Circuit board arrangement

In all I think it took about twenty-six hours to print. I'm happy to say it fits together nicely.

Photo of working terminal 1 Photo of working terminal 2

I realised that this was wasted as just a terminal so I put a Pi 3b+ in there and installed the desktop environment. I put a ZX Spectrum emulator on and realised I'd neglected to a put a speaker in! Something for v2. For version two I'll probably make some of the corners softer by rounding them and make it snap together tighter.

Preventing SYSLOG spam

One of my Raspberry Pis has a problem. When connected to WIFI every few seconds two lines are added to my /var/syslog:

Mar 6 10:13:15 Pi dhcpcd[764]: eth0: Router Advertisement from...  

In this particular example I could fix this by disabling the IPv6 DHCP servive in my router, or disabling IPv6 on the Pi, but for the moment I want to simply keep these messages out of my syslog.

Happily, there's a nice syntax which allows us to add lines to the /etc/rsyslog.conf to filter lines sent to the syslog and prohibit them from being added.

In the case of the example above I added the following line near the top of the configuration file:

:msg, contains, "Router Advertisement from" stop

Then restart with sudo systemctl restart rsyslog and no more junk in the syslog!

sudo in .bashrc

Due to a quirk with the Raspberry Pi's current implementation of Debian I had some trouble mounting CIFS shares at start up. The solution was to run the mount command once logged in, the easiest way to do this is in the .bashrc script.

However! To run the mount -a command to mount all shares requires elevated privileges but I didn't want to have to type password twice at login. The solution to this is add the command itself to the /etc/sudoers with the NOPASSWD flag:

pi    ALL=(ALL)    NOPASSWD: /bin/mount  

One thing to note is that it's important to provide the full path to the command.

Extracting and renaming files from zip archives

I had a pile of zip files all containing different files, but also containing a file called preview.png that I wanted to extract and rename. Since the names of the zip are descriptive I wrote a bash script to loop over the files, extract the preview file and rename it. The interesting bit is stripping the .zip extension.

#!/bin/bash

FILES=./*.zip  
for F in $FILES  
do  
  echo "Processing $F file..."
  unzip "$F" preview.png
  FN=${F%.zip} # strip .zip
  mv preview.png "${FN##*/}.png"
done  

For tar or gzipped tar the following will work in place of the 'unzip' line above:

tar -xf "$F" path/to/preview.png # extract from tar  
tar -zxf "$F" path/to/preview.png # extract from tar.gz  

GeoIP blocking and redirecting on Apache

Recently I was asked to configure a WordPress install to block any traffic from Russia, and redirect any traffic from the USA to another US-centric site.

First thing to do is install mod-geoip for Apache (in my case on Ubuntu):

sudo apt install libapache2-mod-geoip  

Next uncomment the GeoIP database in the GeoIP conf file (/etc/apache2/mods-available/geoip.conf):

<IfModule mod_geoip.c>  
  GeoIPEnable On
  GeoIPDBFile /usr/share/GeoIP/GeoIP.dat
</IfModule>  

Restart Apache:

sudo systemctl restart apache2  

With GeoIP enabled we can apply our block and redirect in .htaccess

GeoIPEnable On

# deny for Russia
SetEnvIf GEOIP_COUNTRY_CODE RU DenyCountry

# redirect for USA
RewriteEngine on  
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^(US)$  
RewriteRule ^(.*)$ https://usa-site.com/$1 [L]  

A list of ISO Alpha-2 country codes can be found on WikiPedia, and many other places online.