Grandstream GXP1610 Reboot-o-matic


I wrote a nice little script to fix a problem I’ve been having with my work VOIP phone. It would lose connection but the screen wouldn’t let you know it had. I didn’t notice that it hadn’t been connected for *two* weeks until someone left a voicemail.

The phone did have a built in SSH interface, which had a reboot command, so I tried using ssh -i key admin@phone < commands.txt to feed it a bunch of commands. I had to pipe a text command to ssh because it doesn’t use a ‘real’ shell on the phone, just Grandstream’s proprietary command interface, which doesn’t accept commands directly when called from ssh.

This was okay, it restarted the phone but it would also reset the password back to ‘admin’. Not very secure really… So I looked for a way to reboot it using the web interface. I fired up Firefox’s network debugger and started to reverse engineer how commands were processed.

I worked out what I needed to do to login as an admin, and then issue the reboot command. It worked. Nice.

sid=$(curl -k -s -c /tmp/cookies.txt -d"password=hunter2" --referer | sed -r 's|.*"sid": "([0-9a-z]+)".*|\1|' )
curl -k -s -b /tmp/cookies.txt -d"request=REBOOT&amp;sid=${sid}" --referer
rm /tmp/cookies.txt

Really though, I wanted a better solution, sure I could reboot the phone every day to make sure it’s working but what would be awesome would be if my script could check to see if the phone was connected to my SIP account, and if it wasn’t, or there was some kind of error, it could reboot it or at least tell me there was an error.

So I wrote version 1 of my script and got it working, when the SIP connection isn’t registered, it will restart the phone.

# Grandstream GXP1610 Reboot-o-matic v1
# Authored on 12/10/2020
# by jcx
# Licence: GPLv3 (or at your option, any later version.)
# Usage: gsreboot [IP/Hostname]
sid=$(curl -k -s -c /tmp/cookies.txt -d"password=hunter2" https://${1}/cgi-bin/dologin --referer https://${1} | sed -r 's|.*"sid": "([0-9a-z]+)".*|\1|' )
status=$(curl -k -s -b /tmp/cookies.txt -d"request=vendor_fullname:P35:PAccountRegisteredServer1:PAccountRegistered1" https://${1}/cgi-bin/api.values.get --referer https://${1} | sed -r 's|.*"PAccountRegistered1": "([0-9a-z]+)".*|\1|' )
if [ ${status} != 1 ]
echo "Requesting reboot on ${1} ..."
curl -k -s -b /tmp/cookies.txt -d"request=REBOOT&amp;sid=${sid}" https://${1}/cgi-bin/api-sys_operation --referer https://${1}
rm /tmp/cookies.txt

Now I just need some way to automate it, which is where cron comes in. Cron will run a command however often you like, so I just set it to every 5 minutes to do a check, and now I won’t miss any more important work phone calls.

*/5 * * * * /usr/local/bin/

Okay, so the first version of the script I wrote, while it works, it isn’t very elegant. It didn’t really report any error messages and wasn’t user-configurable so I’ve rewritten it (v2!) and now it supports some options, and has more sensible error messages.

# Grandstream GXP1610 Reboot-o-matic v2
# Authored on 12/10/2020
# by jcx
# Licence: GPLv3 (or at your option, any later version)
# Please edit the password below to be the admin account on your GXP1610.
# I defined it here so that you don't need to use it on the command line.
# You shouldn't need to make any other changes.
#### Begin Script
if [ -z ${1} ]
    echo "----------------"
    echo "gsreboot2: GXP1610 Reboot-o-matic v2 by jcx ( licenced under GPLv3"
    echo "Usage: [IP/Hostname] [Protocol: http/https] [Ignore Certificate Errors: Y/N]"
    echo "Example: https Y"
    echo "----------------"
    echo "This will connect to the Grandstream phone on"
    echo "using https and will ignore any certificate errors."
    echo "Use with cron every 5 minutes, as it takes the phone about 3 minutes to boot."
    echo "Don't forget to change the password at the top of the script!"
if [ -f "/tmp/gsreboot2.txt" ]
    rm "/tmp/gsreboot2.txt"
if [ -z ${2} ]
if [ "${2}" = "https" ]
if [ "${2}" = "http" ]
if [ -z ${3} ]
if [ "${3}" = "Y" ]
    certignore="-k "
if [ "${3}" = "N" ]
sid=$(curl ${certignore}-s --connect-timeout 10 -c /tmp/gsreboot2.txt -d"password=${password}" ${proto}://${1}/cgi-bin/dologin --referer ${proto}://${1} | sed -r 's|.*"sid": "([0-9a-z]+)".*|\1|' )
status=$(curl ${certignore}-s --connect-timeout 10 -b /tmp/gsreboot2.txt -d"request=vendor_fullname:P35:PAccountRegisteredServer1:PAccountRegistered1" ${proto}://${1}/cgi-bin/api.values.get --referer ${proto}://${1} | sed -r 's|.*"PAccountRegistered1": "([0-9a-z]+)".*|\1|' )
if [ "${status}" = "0" ]
    echo "VOIP account not registered..."
    echo "Requesting reboot on ${1} ..."
    request=$(curl ${certignore}-s --connect-timeout 10 -b /tmp/gsreboot2.txt -d"request=REBOOT&amp;sid=${sid}" ${proto}://${1}/cgi-bin/api-sys_operation --referer ${proto}://${1} | sed -r 's|.*"body": "([0-9a-z]+)".*|\1|' )
    if [ "${request}" = "savereboot" ]
        echo "Reboot request has been acknowledged."
    if [ -f "/tmp/gsreboot2.txt" ]
        rm "/tmp/gsreboot2.txt"
if [ "${status}" != "1" ]
    echo "Error: Cannot determine status of VOIP account."
# Enable this code if you want output on success... disabled by default because it works with cron.
#if [ "${status}" = "1" ]
#    then
#    echo "Success! Your VOIP account is active. No reboot required."
if [ -f "/tmp/gsreboot2.txt" ]
    rm "/tmp/gsreboot2.txt"

Its grown from 18 lines of code to 109(!). This isn’t bad, considering before I wrote these scripts, I’d never written anything in shell / bash script before. So I replaced the entry in my crontab to run the new script every 5 minutes.

*/5 * * * * /usr/local/bin/ https Y

Below is what it looks like in my email client on my Linux box when the SIP account is not registered and it needs a reboot.

Date: Mon, 12 Oct 2020 00:10:07 +0100
From: Cron Daemon <root@localhost>
To: jcx@localhost
Subject: Cron <jcx@localhost> /usr/local/bin/ https Y
VOIP account not registered...
Requesting reboot on ...
Reboot request has been acknowledged.

If the script encounters an error, it will email an error response. This looks like the following:

Date: Mon, 12 Oct 2020 00:35:07 +0100
From: Cron Daemon <root@localhost>
To: jcx@localhost
Subject: Cron <jcx@localhost> /usr/local/bin/ https Y
Error: Cannot determine status of VOIP account.

I hope this proves useful to you, it certainly has to me. Not only because my phone will always be connected but I also learnt how to do some basic shell scripting. Have a great day!

Setting Up Auto Mounting Encrypted Raid Disks


This is a little guide (currently under construction) for how I handle encrypted disks on Linux. This won’t be the ultimate ‘tin foil hat’ guide, as the attack vector this is intended to protect from is physical theft of the hardware, so that the data can’t be accessed from elsewhere. It obviously will not handle a targeted hacking attempt or the $5 wrench method, but I believe it gives security and convenience to a level appropriate for me.

xkcd 538: describing the $5 wrench method of breaking security.

The reason this started is because my physical health is deteriorating and getting up to enter a password at the console on every reboot is tiresome. Therefore I came up with a new way of handling encrypted drives to not only increase security but also make things a bit more convenient.

Of course before following any of these instructions, you should be aware of my standard disclaimer.

Caution – You need to secure the location of where you store your key. If you fail to secure your key with an appropriate mechanism, this entire exercise is fruitless.

Examples include: IP restricting access to your key provisioning system, using a strong username and password, using an easy to revoke token based storage mechanism, verifying HTTPs transfer certificates and countless others.

Included below is a method similar to what I use to secure where I store my keys.

Create a keyfile

dd bs=256 count=1 if=/dev/random | base64 > data-keyfile

Upload the keyfile somewhere, for example a HTTPS server with a valid certificate, or S3 or Azure key storage, and then make a script to download the key from where you put it. If you’re storing your key on a HTTPS server, here is an example htaccess file to secure access to the directory to specific IPs and a user/password section to further increase security. This works with Apache 2.4 but the syntax may be different for later versions.

order deny,allow
deny from all
allow from

Options -Indexes
AuthType Basic
AuthName "Restricted Access"
AuthUserFile "/secure/path/to/htpasswd"
Require valid-user

Once you have uploaded it somewhere don’t forget to delete the original source file securely from your system (for example with shred).

set -e
# Request the file from somewhere, maybe blob storage, asure, S3 or HTTPS Server, then pipe it through `base64 -d` to decode it from base64
curl -s --basic --user username:password "" | base64 -d

Then move the script somewhere and give it the right permissions

# Ensure the owner of this file is "root"
chown root:root /etc/luks/
# Allow only the owner (root) to read and execute the script
chmod 0500 /etc/luks/

Create the raid

# if all drives are already blank and ready to be added. Replace drives as appropriate.
mdadm --create /dev/md2 -l 1 -n 2 /dev/sdc1 /dev/sdd1
# if you need to create a 'degraded' array with a drive missing.
mdadm --create /dev/md2 -l 1 -n 2 /dev/sdc1 missing

Then encrypt the array

# Encrypt the disk
# Replace md2 with the correct array!
/etc/luks/ | cryptsetup -d - -v luksFormat /dev/md2

# Open the encrypted volume, with the name "data"
# Replace md2 with the correct array!
/etc/luks/ | cryptsetup -d - -v luksOpen /dev/md2 data

# Create a filesystem on the encrypted volume
mkfs.ext4 -F /dev/mapper/data

# Close the encrypted volume
cryptsetup -v luksClose data

Find the encrypted partitions UUID

$ lsblk --fs
NAME    FSTYPE      LABEL           UUID
└─sdc1         linux_raid_mem server:1 a38cbabe-0f12-3643-f3232-998822c5d42
  └─md2        crypto_LUKS             a17db19d-5037-4cbb-b50b-c85e3e074864 

Then create a script to run on boot to automount

if [ -b "/dev/mapper/data" ]
		if [[ $(findmnt -M "/disks/data") ]]; then
    		echo "Not mounted but unlocked... trying to mount..."
	mount -t ext4 -o errors=remount-ro /dev/mapper/data /disks/data
		curl -s --basic --user username:password "" | base64 -d | /sbin/cryptsetup -d - -v luksOpen /dev/disk/by-uuid/a17db19d-5037-4cbb-b50b-c85e3e074864 data
		mount -t ext4 -o errors=remount-ro /dev/mapper/data /disks/data

if [[ $(findmnt -M "/disks/data") ]]; then
# Anything you want to run after the disks are mounted
		echo "All disks mounted, starting services..."
		echo "Starting samba..."
		systemctl start smbd

and add it to root’s crontab on reboot.

# m h  dom mon dow   command
@reboot sleep 30 && /etc/luks/

Don’t forget to disable any services you don’t want to run until the encrypted drives are mounted, for example samba

systemctl disable smbd

Create the mount point

mkdir /disks/data

And finally a script to stop encrypted drives (if required)

echo "Stopping Samba..."
systemctl stop smbd

if [[ $(findmnt -M  "/disks/data") ]]; then
    echo "/disks/data is mounted, trying to unmount..."
	umount /dev/mapper/data
    echo "Attempting to close luks on /dev/mapper/data ..."
	if [ -b /dev/mapper/data ]
		/sbin/cryptsetup -d - -v luksClose data
	if [ -b /dev/mapper/data ]
    	echo "/disks/data is not mounted, but is unlocked, will attempt to close ...."
	/sbin/cryptsetup -d - -v luksClose data
	echo "/disks/data is not unlocked or mounted, nothing to do."

This work was inspired by an article on by Alessandro Segala and adapted/changed to meet my requirements.

Debugging Windows 10 at Startup


It’s almost impossible to be able to hit F8 during Windows 10’s start up. The “official” way to get into the boot menu is to let Windows 10 start and get to the login screen, hold the shift key and click “Restart”. The problem with this is, what if you can’t get to the login screen?

Many times I’ve had a simple issue that could be fixed in Safe Mode or using the basic graphics mode available from the boot menu. I’ve found a method that makes this debugging easy and gives you plenty of time to be able to press F8 if you need to on boot, without taking too much time away from the actual boot. It’s a user configurable timeout too, so you can set it to what you want.

Of course before following any of these instructions, you should be aware of my standard disclaimer.

Firstly, enable the Legacy Bootloader, by opening an administrative command prompt.

bcdedit /set "{current}" bootmenupolicy legacy

This will enable the old style operating system selector from Windows 7. Next you set it to display the menu with the following command.

bcdedit /set {bootmgr} displaybootmenu yes

Finally you control how long the timeout is. The default 30 seconds is quite a long time to wait if you don’t press any key, so I use the timeout of 5 seconds, which gives me ample time if I need to get into the advanced boot options menu, but it doesn’t slow down the boot that much if I don’t.

bcdedit /set {bootmgr} timeout 5

That’s it! If you ever need to debug a simple start up issue, you don’t have to find your rescue CD, or reset during boot to launch “startup repair”. It’s saved my skin so many times already 🙂

Audio Terminal Bell (Software Bell) in Xubuntu with xfce-terminal


I have wanted a software audio based terminal bell in linux for years. Similar to in PuTTY on Windows you can chose any arbritary wav sound file as your terminal bell sound, I wanted this functionality on Linux, and I have wasted lots of time over the years trying to get this working. I haven’t had much luck… until today!

I was setting up a new Xubuntu 18.04LTS machine and was going through the preferences in xfce-terminal and noticed it had an option for “Audible Bell” in the advanced features menu. I turned it on and it didn’t work, but it prompted me to try and find a solution again.

Here’s the commands I used to get it working.

sudo apt-get install gnome-session-canberra sox
xfconf-query -c xsettings -p /Net/EnableEventSounds -s true
xfconf-query -c xsettings -p /Net/EnableInputFeedbackSounds -s true
xfconf-query -c xsettings -p /Net/SoundThemeName -s "freedesktop"

Then you need to add the following to the end of your .profile file in your home directory (~/.profile)


Then add the following to /etc/pulse/

# audible bell
load-sample-lazy x11-bell /usr/share/sounds/freedesktop/stereo/bell.oga
load-module module-x11-bell sample=x11-bell

Then restart pulseaudio with

pulseaudio -k

Make sure your “System Sounds” is turned up in the Volume Control applet and finally make sure the following appears in ~/.config/xfce4/terminal/terminalrc under [Configuration]


You can also set this under “Preferences/Advanced/Audible Bell”. You will probably need to logout and logon again, but other than that everything should work. You can change the sound to a .oga file of your choice by changing the path of the sound in the load-sample-lazy command above.

RAID Drive Replacement


On the 20th May, I noticed an email from mdadm (the Linux Raid Administrator) saying that a Degraded Array event was detected. It looked like two drives went down at the same time (SDC and SDD). Before I had done any diagnosis of the problem, I had ordered two replacement refurbished drives.

I went for refurbished because getting new ‘affordable’ drives that don’t use SMR technology (Shingled Magnetic Recording) is difficult. SMR allows more capacity in a smaller area, however they are a lot slower drives once you have filled the 25GB cache and in Network Attached Storage systems, they are not ideal. (Even WD Red NAS drives use SMR and don’t disclose that!)

So I went for some refurbished Seagate Barracuda 2TB drives. These were cheap and they used CMR 🙂

After a bit more diagnosing and a reboot, it looked like the SDC drive was okay but was just knocked offline because SDD corrupted the SATA bus. That made me feel a little safer, as I don’t like running systems with no margins for failure. I did a full set of diagnostics on SDC and reintroduced it into the array and it did a data check and came back online just fine.

I then had to wait a little while for my refurbished drives to arrive from Germany. They took a couple of days to arrive, which I didn’t think was too bad considering the world is kinda messed up right now.

Once the drives had arrived, I started doing my usual round of tests on new drives, to make sure they’ve survived shipping, make sure I’ve not been sold a lemon and also to make sure they’re going to give a decent level of service.

My testing involves using the SMART self test feature, recording those results, zeroing the drive, recording those results, then overwrite the drive 4 times with different patterns and compare that back. Once that’s done I record the results and compare again to make sure there’s no problems that testing has uncovered.

Next comes partitioning the drive. I just copied the partition layout of one of the existing disks and wrote the partition table to the disk. I then asked mdadm to add the new partitions into the RAID devices (md0, md1, md2, md3), and it started to rebuild the missing drive onto the new blank. You can see in the screenshot it is about 9.2% through recovery of the largest md device, md1.

From discovery to fix, this entire process took about 5 days. Actual user input was only about an hour, plus checking back and forth to make sure the drive was behaving.

Of course, RAID is not backup, but it’s great if your system can take two drives failing and still run fine. I have a backup system on a seperate drive and cloud backups. This is because in 2010, I typed an F instead of a G and wiped out the last 10 years.

Checking back through the logs, the problem was first reported on the 5th, but I didn’t see the email alert until the 25th, but at least it’s all fixed now. I didn’t need two drives, but it’s good to have a ‘cold’ spare in stock now 🙂

jcx’s Standard “New Drive” Procedure


Don’t forget: This advice is posted with my Standard Disclaimer. Please read that before proceeding.

01. If the drive is not a new sealed retail drive, check SMART values are okay before testing. (smartctl -a /dev/sdX), save to compare later.

02. Run SMART short test (smartctl -t short /dev/sdX)

03. Run SMART conveyance test (if supported) smartctl -t conveyance /dev/sdX

04. Some drives will only update some SMART attributes if offline data collection is enabled. To make sure, turn offline testing every 4 hours with smartctl -o on and then start an offline test (smartctl -t offline /dev/sdX)

05. Verify drive passed all these tests (smartctl -l xselftest,selftest /dev/sdX). Create a second log file for comparison later.

06. Zero the drive with dd (dd if=/dev/zero of=/dev/sdX bs=4M status=progress).

[!] Keep an eye on the drive temperature (if supported) with smartctl -l scttemp the logged historical data will vary between manufacturers. [/!]

07. After ZEROing the drive, it will have reallocated any bad sectors from the factory. Compare the SMART values to the ones you took at the beginning, paying close attention to Pending and/or Reallocated Sectors.

08. Check the drive’s error log (smartctl -l xerror,error /dev/sdX) to see if there are any reports of non-fatal errors which haven’t resulted in a bad sector.

09. Next comes a full write test. You can either use the long test, using badblocks which will perform 4 full read and 4 full write tests. (badblocks -wvsb 4096 /dev/sdX) This can take tens of hours. If you are in a hurry, you can also use a single pass test. (nwipe?)

10. After completion again check the SMART values (smartctl -a /dev/sdX) and compare them to the original readings.

[!] Some drives also support extended device statistics (smartctl -l devstat /dev/sdX) which can show you some non-standard stuff. [/!]

11. If the drive passes these tests without error it will usually be a good drive. The surface has been written and read from several times to ensure there’s no major problems.

12. If you want to stress test the drive mechanism (actuator/heads) you can use fio to perform small reads/writes at random locations across the entire disk surface. Be sure to keep an eye on the temperatures while doing this. If the drive isn’t properly cooled you might run into problems. It is probably reasonable to run this test for around two or three hours.

AcePC T11 Mini PC with Windows 10 CPU Throttling Fix


I have being trying to fix an issue with Windows 10 on the AcePC T11 Mini PC. It would after a while, only use 33% of its CPU and be limited to 0.48GHz, which made YouTube and other processor intensive tasks really slow.

There are two problems that I encountered on Windows 10. The first was in “Power Options” in the Control Panel there was only the option for Balanced. High Performance and Power Saver were unavailable.

The second problem is the option to disable throttling is not visible by default.

I have created a registry file to allow us access to these options again.

It is recommended to update to the latest version of Windows 10 before applying these fixes, as they might be overwritten by an update.


Windows Registry Editor Version 5.00



The first option CsEnabled restores the hidden options in the Power Options section of control panel.
The second change allows us to modify the option “Processor performance core parking min cores”.

Copy the above to a blank notepad file, and save it as “power-fix.reg” making sure to include the quotation marks. Double click the file you have just saved to apply the registry fix and then you should restart your computer.

Then open the start menu and type Control Panel. Then navigate to “Power”. Chose the High Performance option, then click “Change plan settings”, then “Change advanced power settings”.

Navigate to “Processor performance core parking min cores”, under Processor power management, and set this to 100%.

Then finally, “Allow throttle states” to “Off”.

Apply your changes and reboot. Now your system should not be stuck running at the slow speed of 0.48GHz, but run around 1.44GHz to 1.68GHz

New Playlist


I made a new playlist of songs I currently like.

52 tracks in playlist, average track length: 3:51
Playlist length: 3 hours 20 minutes 46 seconds

Playlist files:

  1. Postal Service, The – Nothing Better (3:46)
  2. Frank Turner – Worse Things Happen At Sea (3:43)
  3. Avril Lavigne – Nobody’s Home (3:32)
  4. Weepies, The – World Spins Madly On (2:39)
  5. Pierre Belmonde – Forever Autumn (3:17)
  6. Icon For Hire – Iodine (2:32)
  7. DHT – Driver’s Seat (2:51)
  8. Jem – Just a Ride (3:20)
  9. Halestorm – Freak Like Me (3:38)
  10. Reuben – Horrorshow (2:58)
  11. Rachel McGoye – Late Night Lover (4:07)
  12. Akon – Never Took The Time (3:57)
  13. Vanessa Carlton – Paint It Black (3:30)
  14. Green Day – Jesus Of Suburbia (9:08)
  15. Ed Sheeran – Drunk (3:19)
  16. Bad Religion – Let Them Eat War (2:57)
  17. Kelly Clarkson – Einstein (2:59)
  18. Tool – 10,000 Days (Wings, Pt. 2) (11:13)
  19. Evanescence – Good Enough (5:31)
  20. Death Cab For Cutie – I Will Follow You Into The Dark (3:09)
  21. +44 – Make You Smile (3:44)
  22. Halestorm – What Sober Couldn’t Say (3:33)
  23. Halestorm – I Like It Heavy (4:55)
  24. Halestorm – Here’s To Us (2:57)
  25. Muse – Uprising (5:02)
  26. Blue Swamp – Jumper On The Line (3:04)
  27. Ed Sheeran – I’m a Mess (4:04)
  28. Newton Faulkner – I Need Something (2:57)
  29. Kelly Clarkson – Since U Been Gone (3:08)
  30. Placebo – You Don’t Care About Us (3:58)
  31. Tom McRae – A Day Like Today (3:48)
  32. Siouxsie And The Banshees – This Wheel’s On Fire (5:42)
  33. Bad Religion – Social Suicide (1:35)
  34. Against Me! – Dead Friend (3:02)
  35. Placebo – Special Needs (5:15)
  36. Seether – Remedy (3:27)
  37. Halestorm – Dear Daughter (4:46)
  38. Bad Religion – God’s Love (2:32)
  39. Ed Sheeran – Small Bump (4:18)
  40. Reuben – Good Luck (3:35)
  41. Android Lust – The Body (5:23)
  42. Icon For Hire – Get Well (2:57)
  43. Ed Sheeran – Little Bird (3:45)
  44. Halestorm – Love Bites (So Do I) (3:11)
  45. Jay Nash – Over You (4:00)
  46. Kelly Clarkson – Behind These Hazel Eyes (3:18)
  47. Fightstar – Unfamiliar Ceilings (4:06)
  48. Placebo – English Summer Rain (4:01)
  49. Jewel – Hands (3:55)
  50. Kelly Clarkson – Miss Independent (3:34)
  51. Against Me! – True Trans Soul Rebel (3:12)
  52. Weepies, The – Nobody Knows Me At All (1:56)