Category Archives: Tech

tech

‘Check WordPress Update’ plugin for Nagios — PHP 8 compatibility

If you’re using Nagios to monitor your WordPress installations, you may be using the ‘Check WordPress Update’ plugin by jinjie found here:

https://exchange.nagios.org/directory/Plugins/CMS-and-Blog-Software/Wordpress/Check-WordPress-Update/details

We recently updated our PHP version on some of our servers to version 8, and this broke the old version of the plugin. The new plugin has been updated and is compatible with PHP version 8.

The incompatibility was with the last line in the code:

echo $status . '#' . implode(';', $text);

The issue arises because of the order of the arguments for the implode function. The old signature, used for PHP versions up to 7.4 was:

implode(array $array, string $separator): string

whereas the new signature for PHP versions greater than 7.4 is:

implode(string $separator, array $array): string

If you’re on a machine which hosts multiple PHP versions and want to just use one version of the plugin, you can use this little modification to check the current PHP version:

//Test if we're using php version 8 or greater.  This fix is needed or a fatal error will occur.
if (version_compare(phpversion(), '8', '<')) {
    // php version is below 8
    echo $status . '#' . implode($text, ';');
} else {
    echo $status . '#' . implode(';', $text);
}

Windows Keyboard Shortcuts!

I just came across this Tweet by @Rainmaker1973, which is sharing a video by someone called lklogic on TikTok. I found it very useful. I’ve used most of these, but didn’t know about Control D to set to the Default Font Set or that you could align text via a shortcut with Control L and R.

You may want the text version, so I recreated it here:

  • Control A = Select All
  • Control B = Bold
  • Control C = Copy
  • Control D = Default Font Set
  • Control E = Center
  • Control F = Find
  • Control G = Go to
  • Control H = Replace
  • Control I = Italic
  • Control J = Justify
  • Control K = Hyperlink
  • Control L = Alight Text to Left
  • Control M = Hanging Indent
  • Control N = New Document
  • Control O = Open
  • Control P = Print
  • Control Q = Add Space after Paragraph
  • Control R = Align Text to Right
  • Control S = Save As
  • Control T = Left Indent
  • Control U = Underline
  • Control V = Paste
  • Control W = Close
  • Control X = Cut
  • Control Y = Repeat / Undo
  • Control Z = Undo

PureText Plugin: Paste raw text only!

Hey folks. One of my Windows pet peeves is that it always copies formatting whenever you use Control-C to copy text. I almost never want to paste formatting anywhere. In fact, sometimes the formatting interferes and it wastes time because I have to either remove it, or remember to first paste in TextPad and then copy again from there.

I was thinking of writing a Windows plugin to only paste raw-text, but it looks like someone named Steve Miller has already come up with one. It’s called PureText. You can download it here:

https://stevemiller.net/puretext/

It’s available from the Microsoft Store, or from that link.

Unfortunately, you can’t replace Control-V as the standard Hotkey for PureText, as this conflicts with Windows. You can use Win or Alt.

Be sure to check out the Options!…

Using grep to query the nameservers of a list of domains

Let’s say you have a text file containing a list of domains you want to query using whois. Our goal is to query each domain in the list an extract the nameservers for each domain.

This can be achieved using a bash script with a combination of whois, grep, and tr.

Examine the following code:

#!/bin/bash
input="domainlist.txt"
while IFS= read -r line
do
        WHOISOUTPUT=$(whois $line | grep "Name Server" | tr -d '\n')
        echo "$line," "$WHOISOUTPUT"
        sleep 3
done < "$input"

This script instructs bash to run a whois command on each line of the input file. The variable $line will contain the domain name, grep will pick out the lines containing “Name Server”, and tr -d ‘\n’ will remove the new lines from the preceding text in the pipe so the output will appear on one line.

So your output will look something like:

domain.com,    Name Server: ns1.nameserver.com    Name Server: ns2.nameserver.com
domain2.com,    Name Server: NS1.MYDNS.com    Name Server: ns2.MYDNS.com

We are Grepping “Name Server” because that follows the output format outlined by ICANN https://www.icann.org/resources/pages/approved-with-specs-2013-09-17-en#whois

Please be aware that sometimes whois servers can return non-standard formats.

The ‘Sleep 3’ statement is there just to be polite and not hammer nameservers.

If you pipe the output of this script to a text file and save it, you can open it as a CSV file.