Mostly about my amusement

Author: Jan Dembowski (page 3 of 96)

So! You like retro game systems?

One of my recent hobbies (aside from breaking my WordPress site) is anything related to the Raspberry Pi. I use it as a network media player in my living room, USB computer on a stick and as a retrogaming console.

Nintendo recently released the NES Classic Edition which comes with 30 built in games. This holiday season it will be a big hit and it sold out almost as quickly as it was released. With a Raspberry Pi 3 running Retropie you can accomplish almost the same thing. It just takes a little geeky work and some parts.

Here’s the parts and links. I usually just drive out to Micro Center in Westbury and get it in person.

Raspberry Pi 3 $29.99 Micro Center
Raspberry Pi 3 case $8.99 Micro Center
USB charger (5 volts, 2.4 amps) $8.99 Micro Center
Microsoft Xbox 360 wireless controller for Windows 2 x $35.99 Best Buy
32GB microSD Class 10 $10.99 Micro Center
6′ HDMI cable $6.99 Amazon
Total: $137.93

OK, that added up quickly. The NES Classic Edition is $59.99. Add another $9.99 for a second wired controller and you’re only in for $69.98.

I begin to see what Lily means. Grownup’ing is a pain.

The XBox 360 wireless controllers that I linked to also include a USB transceiver. That part number JR9-00011 is cheaper than just a controller alone. I don’t know why.

Just about any USB game controller that works with your PC will work with Retropie. I picked these because I had a spare and I like being able to sit on the couch while playing.

Download and burn the Retropie image

Visit Retropie’s download page and make sure you get the one for Raspberry Pi 2/3. At the time of this post that’s version 4.1

I’ve never tried burning the image using a Mac. On a PC I just use 7Zip to expand the retropie-4.1-rpi2_rpi3.img.gz and use Win32 Disk Imager to write it to the microSD card.

There are some really good detailed instructions for installing and configuring Retropie here.

https://github.com/retropie/retropie-setup/wiki/First-Installation

When it boots you will be asked to configure your controller so you’ll need to get your XBox 360 controllers working.

think the Xpad driver ships and is activated by default. I don’t recall activating it myself. If that’s not the case then I’ll update this post.

  1. Put batteries into your XBox 360 controller, and plug the XBox 360 Wireless USB transceiver into any free port on your Pi.
  2. Press the stylized XBox button on your controller to turn it on and then press the button on the transceiver.
  3. The front of your controller has a not quite recessed wireless sync button. Press that and your controller will connect to your USB transceiver.
  4. Press a button on your controller to begin configuring it.

From the Retropie Git docs, you’ll configure the buttons like so.

The image is from that Retropie installation page. I didn’t want to hotlink the image as that’s rude. If it’s a problem I’ll remove the image.

You will get some of the button assignments wrong. Don’t worry, as long as you get the D-PAD, START button and A button assigned then you can redo it later on.

That USB transceiver supports up to 4 controllers. When you use PS2 emulation for games it not only works but so does the rumble part. That’s cool.

Network your Raspberry Pi 3

I happen to have an Etherenet connection onto my Raspberry Pi 3.  It also comes with a built in 802.11n wifi adapter. You want your Retropie on your network and being able to ssh to it is very useful.

https://github.com/retropie/retropie-setup/wiki/Wifi

Borrow a USB keyboard from your PC or Mac so you can enter your wifi key. You won’t need it afterwards. I do all my Linux admin via ssh from my PC or Mac.

Your Raspberry Pi 3 running Retropie is a Linux server. It’s running a Debian based distribution called Raspbian. If you’ve spent time administering an Ubuntu LTS VPS then this will feel very similar if not downright identical.

The reason for getting your Retropie on the network is simple: once you do you will find a new Windows share at \\RETROPIE and you can deposit the NES ROMs you obtain in \\RETROPIE\roms\nes as easy as drag-n-drop.  You’ll have to do some research where to get them yourself. They’re not hard to find.

When you do obtain NES ROMs make sure you keep them in individual ZIP archive files. Don’t extract them, just from them as is into your nes directory. Once you’ve gotten your roms onto your new system, press the “start” button on your controller and restart emulationstation.

So many emulators to use

Retropie supports many retro arcade systems. My favorite are MAME, SNES, NEO GEO and of course NES. I don’t play a lot of Atari 2600 games though I should. That’s one of the systems I had as a kid.

The emulators are easy to use. Generally you just drag the ROM zip file into it’s directory. Use \\RETROPIE\roms\nes and \\RETROPIE\roms\snes for the  right one. You’ll see many more directories there but for now ignore them. You can explorer them later.

This is not a game system for everyone

If you are just looking for the classic NES games and can get your hands on one even with the small controller cables, then do so.

This illustrative YouTube video can explain the mindset of people who do this sort of thing.

https://www.youtube.com/watch?v=KxwcQ1dapw8

You’ll either immediately understand where I’m coming from or you wont. That’s OK, some people just enjoy the nerdy aspects of things.

Using a Raspberry Pi 3 with Retropie is purely a geeky exercise. It works, it works well. It’s easy to maintain provided you are willing to learn the Zen of the Debian Based Linux Server™

Part of the appeal of the Raspberry Pi 3 is that it is a server with a quad core ARM CPU running at 1GHz. It has 1 GB of RAM built in. With a 32GB microSD card, case, and A/C adapter it’s a full on Linux server for less than $70.

Setting up a small PC with similiar stats will run you at least $200. The small size of the Raspberry Pi 3 shouldn’t take away from the fact that it is a Linux server. It has a default user ID and password. You should change that if you’re concerned.

Here’s an example of what I mean. Yesterday I did the following.

  1. ssh’ed to the retropie as the pi user.
  2. Ran sudo apt-get update ; sudo apt-get -y upgrade ; sudo apt-get -y dist-upgrade
  3. Ran cd Retropie-Setup then sudo ./retropie_setup.sh
  4. Selected “Update all installed packages” and skipped the OS ones because I already did those.
  5. Had coffee. See illustrative video above.
  6. Ran sudo reboot to reboot box.

If you read that, stopped at step 2 and said “Are you kidding me?” then it’s alright. You’re OK. The NES Classic Edition is for you, it’s $60 and it is fire and forget. It does not have any network capabilities, it will never be updated. And there’s no legal question about using one either.

If you want to roll your own and don’t mind getting up to your neck in Geeky Nerdy things then maybe the Raspberry Pi 3 is for you.

Scrape IFTTT Instagram media into WordPress

I’m a photography nut. I love using my DSLR, I’m mad about film cameras and I use Instagram all the time. I’m also a WordPress user and I have a problem with Instagram: the photos are not preserved on my own site. To fix that I installed the amazing DsgnWrks Instagram Importer plugin and I’ve been using it for years.

While testing WordPress 4.6 beta the plugin stopped working for me. I raised a support topic and I am convinced that my setup has changed. I do not doubt that the problem is mine somehow.

I’m not proficient enough to locate where the break is and I really wanted to share my Instagram photos via my blog. So I created another WordPress account on my photo blog and with my IFTTT account I used this “Instagram to Blog” recipe. That worked, but it loaded the image from Instagram and used the IFTTT URL shortner for link.

I really wanted a copy of my photo on my own server.

I know less about IFTTT recipes than I do the plugin. But I do know how to use WordPress actions and filters so I wrote a small plugin to do the following.

  1. Via the publish_post action look in the content for Instagram image sources and extract those URLs. The wp_extract_urls function is made for this.
  2. When found import those into the WordPress Media Library and attach it to the post using media_handle_sideload.
  3. Make that new attached image the featured image for the post.
  4. Look for IFTTT short URLs and expand them using a simple function I wrote.
  5. Once that’s done then publish the post.

You can view the code via this Gist link. I have that saved and activated as a plugin on my photo blog.

This isn’t the ideal approach for me but it works. The IFTTT recipe successfully publishes a post when I submit a photo to my Instagram account. I’m taking that data and scraping images from another web site. Generally speaking that’s not cool but until I find a cleaner way to do it I’ll have to live with it.

Firefox and TLS

Firefox is weird. In a forum conversation (which went so off topic but that’s alright) the following was reported to me. When you visited my site in Firefox, you get a warning about being insecure.

Huh. That’s odd and a little embarrassing. I mean, I’m a network security professional so you can see how that would be awkward. 😉

So I looked at my site on the Qualys SSL Labs page and got this result.

Screen Shot 2016-08-07 at 9.35.58 AM

Which is good but Firefox still didn’t like my site.

A few weeks ago I was playing with my nginx config and something I did made Firefox unhappy. I’m pretty sure I munged the cypher suite in my poking and prodding.

Fair enough, I used the configs from a site that does work in that browser and tonight I’ll play around to see what I broke. In the meanwhile my site is encrypted and viewable in Firefox.

Confirmed: I’m not getting the PC back anytime soon

This may fall under category of "bad parenting" but probably not. I hope not. Just don't tell Lily, OK?

My daughter saw all of the fun her brother has playing Team Fortress 2 and wanted in on the action. The kitchen iMac doesn't play games very well but my PC does. So I set her up on an account there, logged her into Steam and the rest was history.

She picked up TF2 quickly. Then she saw that she could play Borderlands 2, Torchlight II, Portal 2 (is there a "two" thing going on?) and spent hours on the PC.

Her normal activity is drawing on the iPad. She's really good and has developed a real skill. Video games are normally the domain of her brother. But they seem to like playing on the same TF2 server. When they're on the same team she plays the medic and supplies health to the other players. When she's on different teams she plays the scout.

She spent the whole evening playing and I had no clue. It wasn't till I went to turn off the light in the office that I saw her. Her mother would not be happy had she walked into the room.

There is hope that the has inherited Lily's Adult Supervision™ genes. I told her that I'd get a third PC for her, probably from Costco. Her answer?

That's wasteful. I can share yours when you are not using it.

I have no idea where she picks that stuff up. I've certainly never encouraged that sort of behavior.

I might be overthinking my son’s TF2 server

My son plays Team Fortress 2 a great deal and wanted to host his own server with mods for him and his friends to play on. Rather than using his PC for that I created an account for him on the Linux basement server.

I downloaded the Linux dedicated server, did a little port forwarding, a few small scripts with screen and POOF! he can now run and manage his own TF2 server. I need to email him some troubleshooting steps but it’s pretty basic even with SourceMods. It works.

Except I’m using FIOS and my IP addresss changes from time to time. The basement server does update it’s DNS entry via Namecheap but TF2 favorites work by IP address.

When the address changes the port forwarding still works but my son’s friends can’t find the server. The IP address changed and their favorite is gone. That sucks.

IP Tables to the rescue

I happen to have a fixed IP address on the Internet. This web server. I don’t have to run the dedicated server on my VPS, I just have to port forward TCP and UPD ports 27015 to the FIOS router.

  1. My basement server keeps the dynamic DNS name updated with the external IP address.
  2. My web server runs script every hour to see if the IP address changed for that DNS entry.
  3. If it did change then it deletes just the old iptable rules and re-add them with the new IP address.

I found a useful bash script for targeting specific rules in named sections of iptables. Why re-invent the wheel? 😉

Here’s the script.


#!/bin/bash
CURRENTIP=$(dig +short tf2.dn7.me | tail -1)
OLDIP=$(</var/cache/tf2.dn7.me-ip)
if [ "$CURRENTIP" != "$OLDIP" ]
then
# Delete existing /sbin/iptables rules for port 27015
# From http://serverfault.com/questions/401416/iptables-clear-all-prerouting-rules-with-a-specific-destination-address
# Remove PREROUTING rules for destination port 27015.
for line_num in $(/sbin/iptables –line-numbers –list PREROUTING -t nat | awk '$8=="dpt:27015" {print $1}')
do
LINES="$line_num $LINES"
done
# Delete the lines, last to first.
for line in $LINES
do
/sbin/iptables -t nat -D PREROUTING $line
done
unset LINES
# Remove FORWARD rules for destination port 27015.
for line_num in $(/sbin/iptables –line-numbers –list FORWARD | awk '$8=="dpt:27015" {print $1}')
do
LINES="$line_num $LINES"
done
# Delete the lines, last to first.
for line in $LINES
do
/sbin/iptables -D FORWARD $line
done
unset LINES
# Add /sbin/iptables of server's new IP
/sbin/iptables -A FORWARD -d $CURRENTIP -i eth0 -p tcp -m tcp –dport 27015:27015 -j ACCEPT #forward tcp port range
/sbin/iptables -A FORWARD -d $CURRENTIP -i eth0 -p udp -m udp –dport 27015:27015 -j ACCEPT #forward udp port range
/sbin/iptables -t nat -A PREROUTING -d 172.99.75.122 -p tcp -m tcp –dport 27015:27015 -j DNAT –to-destination $CURRENTIP
/sbin/iptables -t nat -A PREROUTING -d 172.99.75.122 -p udp -m udp –dport 27015:27015 -j DNAT –to-destination $CURRENTIP
/sbin/iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
# Save the current IP
echo $CURRENTIP > /var/cache/tf2.dn7.me-ip
# Done
fi

I registered the server on Gametracker and the banner works fine.

 

It works and while the server’s actual IP address changes this will let others find my server. I only change my web server’s host once every few years so this will remain in place for a long time.

They like Minecraft maps. I don’t know why but that’s alright.

 

How to use UpdraftPlus when The Bad Thing™ happens

I am in the process of handing over a site to someone who's not used WordPress before and doesn't necessarily know where what lives and how. I thought it would be a good idea for me to document how to use the free UpdraftPlus plugin.

I use the commercial version of this plugin because it is fire-and-forget for my multisite installation. But if you are running a standalone installation of WordPress then the free version is a good suitable option.

Read more

Did I mention I like WP-CLI?

I’ve written praise for wp-cli before but it’s a toy that will never get old for me.

I was working on this problem for a friend and I needed to create a test multisite installation. I have a domain I can use aside from my main one so I setup another nginx virtual host, setup the DNS entries and used Let’s Encrypt to obtain legitimate X.509 certificates.

For creating the DB and WordPress config I used CLI commands.

$ mysql -u root -p

create database leeloodallas;
grant all privileges on leeloodallas.* to 
"brucewillis"@"loc1alhost" identified by "5oM3U36ul$tringH3re";
flush privileges;
exit;

$ wp core download

$ wp core config --dbname=leeloodallas \
--dbuser=brucewillis \
--dbpass=5oM3U36ul$tringH3re \
--extra-php <<PHP
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );
PHP

$ wp core install --admin_user=yourlogin \
--admin_password=Y3a2n0tHaP3n1ng \
--admin_email=you@example.com \
--url=blog.dn7.me \
--title="Leeloo Dallas Multisite"

$ wp core multisite-convert --subdomains

Yes, all the passwords and IDs are changed.

When I get into deep water (and I did) I just rm * -rf in the virtual host’s directory and in mysql drop database leeloodallas; and do it all over again.

The only thing different from other times is the wp core multisite-convert --subdomains command. I already have cookie cutter nginx configs and DNS is fire and forget. Once I had the vhost setup the Let’s Encrypt commands (also scriptable) was trivial.

WP-CLI is cool and scripting this is such a time saver.