Skip to content

Simple HTTP Server with WebUI and REST API for Sending WoL Package over the Wire

License

Notifications You must be signed in to change notification settings

DualBit/go-rest-wol

 
 

Repository files navigation

GoLang HTTP Server for Remote WOL and Shutdown Requesting from an CSV Computer List

A HTTP server who sends a Wake On LAN package on an HTTP request, and can shutdown a Windows computer with WMI correctly configured.

I followed this article (https://www.howtogeek.com/109655/how-to-remotely-shut-down-or-restart-windows-pcs/) to configure WMI

Docker Image

Simple bootstrap UI for easy usage

Screenshot

Simple REST API to let a machine wake someone up

/api/wakeup/computer/<hostname> - Returns a JSON object

{
  "success":true,
  "message":"Succesfully Wakeup Computer Computer1 with Mac 64-07-2D-BB-BB-BF on Broadcast IP 192.168.10.254:9",
  "error":null
}

Simple REST API to shutdown a machine

/api/shutdown/computer/<hostname> - Returns a JSON object

{
  "success":true,
  "message":"Shutdown of remote machine succeeded",
  "error":null
}

Enviroment Variables

Variable Name Description
WOLFILE Define the port on which the webserver will listen to (Default: 8080)
WOLHTTPPORT Path to the CSV file containing the list of hosts (Default: .\computer.csv)
WOLUSER Define the username of the remote computer (Default: user)
WOLPWD Define the password of the remote computer's user (Default: password)

Commandline arguments

Commandline argument Example Description
--port --port 80 Define the port on which the webserver will listen to (Default: 8080)
--file --file comp.csv Path to the CSV file containing the list of hosts (Default: .\computer.csv)

Computer list file CSV layout

Columns

<name of the computer>,<mac address of the computer>,<broadcast ip to send the magic packet>,<real ip to send the shutdown request>

Example

name,mac,ip,realip
Computer1,64-07-2D-BB-BB-BF,192.168.10.254:9,192.168.10.44
Computer2,2D-F2-3D-06-17-00,192.168.10.254:9,192.168.10.52
Computer3,FF-B3-95-62-1C-DD,192.168.10.254:9,192.168.10.108

Docker

Docker Image: palla89/go-rest-wol-shut

docker build -t go-rest-wol .
docker run go-rest-wol

If you want to run it on a different port (i.e.: 6969) and also want to provide the CSV file on your host:

docker run -e "WOLUSER=alberto" -e "WOLPWD=mypass" -p 6969:8080 -v $(pwd)/externall-file-on-host.csv:/app/computer.csv dabondi/go-rest-wol

If you want to run the WOL Webserver Process in the Webserver on a different Port:

# Used if you run in Network Host Mode
docker run -e "WOLHTTPPORT=9090" -e "WOLUSER=alberto" -e "WOLPWD=mypass" -p 9090:9090 -v $(pwd)/externall-file-on-host.csv:/app/computer.csv dabondi/go-rest-wol

This was a good exercise to learn Golang (and refresh my Docker skills).

A LOT of credit goes to https://github.com/daBONDi/go-rest-wol for the Wake on Lan docker image, I just implemented the shutdown code following your code template, THANKS!!! (I had my first dive in Go too!)

Thx https://github.com/sabhiram/go-wol for the WOL code, sorry that I stole it from you, because I got no clue how I can inject it into my program. :-(

If you have any good ideas, I'm open for pull requests.

About

Simple HTTP Server with WebUI and REST API for Sending WoL Package over the Wire

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 66.9%
  • HTML 29.2%
  • Dockerfile 3.9%