Emblem

Electronic Bondage Safe for Emlalock - Software

EarRing

I finally got around to writing the software for my hacked up safe.

One requirement I had was to let it be usable with sites like Emlalock. Another requirement was to allow the password to be set by my Lady, remotely.

This second requirement kinda meant it'd be easiest to do as a web site, with internet connections forwarded via the router.

In case other people also want to use this software, I decided to write it in Go; now Linux, Windows, Mac and other users could run it on their machines.

So, here it is. That zip file is 7Mb in size and contains the source, plus binaries, and the web site.

Note that at least once Windows Defender false alerted on the windows binary. If you don't trust my compilation then read the source and compile it yourself.


Source code

The zip file contains a number of files. The source code is in the safe.go, vend, vendor, build.sh files. You don't need these to run the program. If you want to recompile it yourself then set GOPATH and run go build safe.go. The build.sh script does this for Linux/MacOS.

Running the code

What you do need is one of the executables, for your OS (eg safe.linux.amd64) and the static/ directory. This directory contains the web site contents, and a simple JPEG image file, which we'll discuss later.

Running the code may be as simple as running the binary. With no additional configuration it will run the web server on port 5000 and try to find the safe on a default serial port (/dev/ttyUSB0 or COM1:).


Set up

The default values are probably not correct for you. You might see an error such as:
    $ ./safe.linux.amd64 
    Using configuration file /home/bdsm/.safe.cfg
      Serial Port = /dev/ttyUSB0
      Listen Port = 5000
      HTML static = /tmp/safe/src/safe/static
      Lock image loaded

    Could not open serial port: open /dev/ttyUSB0: no such file or directory
The first line lets you know what configuration file can be used to override the defaults.

On Windows it will look for %HOMEDIR%%HOMEPATH% or %USERPROFILE. On Linux/MacOS it will look in $HOME. Examples may be:

    C:\Documents and Settings\bdsm\.safe.cfg
    C:\Users\bdsm\.safe.cfg
    /Users/bdsm/.safe.cfg
    /home/bdsm/.safe.cfg
This file is a JSON format file.
    {
      "ListenPort":12345,
      "SerialPort":"COM3",
      "AuthUser":"username",
      "AuthPass":"password",
      "HTMLDir":"/path/to/static"
    }
Each line is optional. The smallest file might be
    {
      "SerialPort":"COM3"
    }
If you have multiple lines then separate them with a ,

ListenPortDefaults to 5000. What port to run the webserver on
SerialPortDefaults to COM1 or /dev/ttyUSB0. Where the safe is
AuthUserIf set, require this username/password for the website
AuthPassSee AuthUser
HTMLDirIf the code can not find the static directory, you can set it here

If you plan on making this available over the internet (eg a remote keyholder) then I strongly recommend setting AuthUser and AuthPass.

On Linux, if you have multiple USB serial ports then it may make sense to use the /dev/serial/by-id/... path to the serial port, rather then /dev/ttyUSB... values to ensure that the right serial port is picked up (just in case the order changes on next reboot).


Successful startup

Once you've correctly configured the software, the startup would look something like:
    Using configuration file /home/bdsm/.safe.cfg
      Serial Port = /dev/serial/by-id/usb-1a86_USB2.0-Ser_-if00-port0
      Listen Port = 12345
      HTML static = /tmp/safe/src/safe/static
      Lock image loaded
      Successfully connected to Safe
      OK Safe is unlocked
The "Successfully connected" means it was able to talk to the safe. The last line is the current state of the safe.

You can now access the website. In this case, I'm running on port 12345 and so http://localhost:12345 would work.

You can see that web site design isn't my strong point. This could have been written by somebody back in 1996... and will probably still work in a browser from that time!

The controls are in the left frame, and the results on the right.


Keyholder use case


Self lock use case

It's strongly recommended to do a test session (eg 1 minute) to verify that this works as you expect. With the door closed and the safe locked (eg with a picture) then you can't open it again if there is a problem, without the backup key.


Restarting

The safe can be powered down and powered up again. The PC software can be stopped and restarted. It should all automatically recover. If the serial port is disconnected while the software is running then you may need to kill and restart the software. But don't worry; the password is stored safely inside the Arduino and the safe is kept locked :-)