This tool will allow you to deploy your own Web Panel + REST API for managing your devices's power status. You can expose it using port-forwarding, VPN or tunneling to allow for Wake on Wan capabilities.
If you found this to be useful for you, a ⭐STAR to the repo would be awesome.
From version 0.0.8 onwards, this API is compatible with this project Remote Shutdown API Service.
This tool will allow you to deploy a REST API for remotely shutting down your devices.
Today, we are creating an interactive web panel for waking up your devices but with a grain of salt.
While we always talk about WoL, we normally don't talk about what happens when you are outside your network.
The so-called "Wake on Wan" is something I have been doing for quite some while now via different methods like SSH snippets and Amazon Alexa.
I have built a desktop app similar to electron based GUIs. I have no repo for it, but if someone is interested in it just ask me about it.
While Amazon Alexa's WoL tool is quite convenient, it's a paid option once you reach a specific amount of devices or for some extra functions.
I have it and still plan to use it from time to time, but adding new devices is a bit of a hassle, it requires two third-party services to be up and let's be honest, for the "I control my devices" kind of user, it's not a viable option at all.
JuiceSSH is also a very convenient way of executing a "wol.sh" script, but again, snippets are a paid feature.
While cloud is getting more and more common, having solutions for us that we have our own on-premise HomeLab is always a pro, since we really "own" our infrastructure.
In this section, we are going to expose a Spring Boot application written in Java 1.8 (for legacy support), deploy, containerize and secure its access.
-
Linux*Any computer capable of running Java (I am using an ODROID-XU4)
* Since version 0.1.2 a Windows computer should also be able to send WoL packets using this tool.
-
Wakeonlan packet installed (optional since 0.1.2)
-
Sreeen, NoHup or Tmux packet installed
-
Ability to port-forward and open up ports
-
Ability to VPN or Tunnel your connection
-
Docker
-
Certificate or OpenSSL Self-Signed Certificate
-
Maven
We are going to first build our project and generate our jar file using maven. Make sure to have maven in your PATH. We will possition ourselves at the root of our project and run:
> mvn clean install -DskipTests
Then we will copy our generated "wol.jar" file to a folder in our Linux box and switch to that folder
WinSSH File Transfer
Let's make sure that we are running a compatible Java VM and that we have it added to PATH:
Let's start a background process with our Spring Boot application, since I'm running SSH, I need the app to stay deployed once the SSH session is terminated. I will use screen package for this.
So we run "screen" command and skip the documentation by pressing Enter or Space.
Once inside a screen session we run our *.jar file:
sudo java -jar wol.jar
By accessing our device's ip using port 7800 (default) using our favourite web browser, we will be presented with this landing login page:
Configuration for this login page can be located in our application.properties:
Once we successfully log in, we will see our configured machines and their online status:
We can then turn on our devices by clicking on the power button of each machine, we will be prompted before turning them on to prevent accidentally powering on a device.
Once our device turns on and is visible network-wise to our web server, we will see that the icon will automatically change to a green-bar signal icon.
There is a file in resources called "devices.json" where you can add, edit or delete devices.
The file follows this structure, we can omit the status value but I am adding it for coherence:
[ {
"description": "ARM Linux Server",
"id": 3,
"ip": "192.168.12.140",
"mac": "00:1e:06:32:1b:9e",
"name": "ODROID-XU4",
"status": false
} ]
We are all done here, we learned how to deploy, change user/password, manage devices and have our service running in the background.
In order to access our device from outside our network, which is the main attractive of our webapp, we will need to expose this port to the internet.
No worries as those tech savvy will be able to implement a tunnel to their internal network so as to not expose this web panel unless you tunnel in!
The first step here is to get the local IP of the device running our WoL Web Service:
We have to add a rule on our router targeting our internal device's IP address:
Then, if everything went well and the service is up, by using our external IP address we should be able to access our Wake on Lan (Wan), web panel.
One of the ways we can secure our connection is by using a VPN client or an SSH Tunnel.
In this example I am going to be using yet another one of my tools, SSH Tunnel Manager.
I have a user set up only for proxying on my ODROID-XU4, I will be showing an example on how to do it with my current setup, but since this is a bit more complex it's a bit out of scope for this article. You can find more info on the project's GitHub pinned here or on my web portfolio's personal project's section:
So, since I have a connection already configured to the same device I am deploying this tool to, I can just create a local tunnel with this simple configuration:
I will just click on Run Tunnel to establish a tunnel that secures the connection towards the WoL Web Panel:
Now, by accessing localhost, via the port 8888 we are actually accessing our device's internal IP at port 7800. So we are essentially redirecting our traffic securely via SSH.
Notice, that the URL doesn't say HTTP, but HTTPS. In the next steps we will be learning how to add self-signed certificates to our Spring Boot application to further encrypt our transfered data.
We won't get too much into the details here on creating a self-signed certificate since that is not the scope of this article, but you can follow this great guide on how to create your own self-signed certificate.
In order to add our newly created certificate to our Spring Boot application we will add this configuration to our application.properties:
Yes, it really was that simple to add HTTPS to our Web Panel.
In order to containerize and deploy this tool, with docker engine installed you can create this two files:
File: dockerfile
FROM openjdk:17-jdk-slim
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} wol.jar
ENTRYPOINT ["java","-jar","/wol.jar"]
File: deploy.sh
docker build -t "wol_api" .
docker run -d --name "WoL_API" -p 7800:7800/tcp "wol_api"
Create a new folder called target, and put inside your generated wol.jar.
You should have a structure similar to this one:
Add permission to deploy.sh to run it:
sudo chmod 755 deploy.sh
Then just run the deploy script:
. deploy.sh
You should now have a running container called WoL_API and endpoint https://0.0.0.0:7800/ should now be accessible.
From version 0.0.8 onwards, this API is compatible with this project Remote Shutdown API Service. This tool will allow you to deploy a REST API for remotely shutting down your devices.
You can run this remote shutdown service on your devices for allowing the web panel to shut down other devices on your network.
It is compatible with theese hosts:
- Windows
- Unix
- MacOS
- Solaris
Position yourself at the init.d folder:
cd /etc/init.d/
Paste the contents of the file in this repo named wolapi_linux_service_template into a file named wolapi.
Execute the following commands as root:
chmod +x wolapi
chown root wolapi
chgrp root wolapi
update-rc.d wolapi defaults
systemctl daemon-reload
You should now have a service called wolapi running that will start on boot.
There are may be many ways to power on your devices when you are not at home, but we developed our own solution for this task that just works and provides a high security while having full control over it.
Native Java WoL packets (0.1.2) based on: https://github.com/Cyecize/Remote-Wake-On-Lan-Web