Code Monkey home page Code Monkey logo

sleep-on-lan's People

Contributors

majorpeter avatar skrimix avatar sr-g avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sleep-on-lan's Issues

Log file or event log on Windows?

Hi! I'm trying to use this very interesting tool and got it working flawlessly on Linux, but have some issues on Windows 10.
I have a config like this:

{
  "Listeners" : ["UDP:9", "UDP:7", "HTTP:8009" ],
  "LogLevel" : "INFO",
  "ExitIfAnyPortIsAlreadyUsed" : true,
  "AvoidDualUDPSending" : {
    "Active": false,
    "Delay": "100ms"
  },
  "Commands" : [{
     "Operation" : "sleep",
     "Command" : "c:\\bin\\psshutdown.exe -d -t 0 -v 0",
     "Default" : true
   }, {
     "Operation" : "reboot",
     "Command" : "c:\\windows\\system32\\shutdown.exe /r /f /t 0 /d u:0:0",
     "Default" : false
   }, {
     "Operation" : "killgames",
     "Command" : "C:\\Windows\\System32\\cmd.exe /c d:\\home\\Serge\\bin\\vanya-killgames.cmd",
     "Default" : false
   }]
}

And I found that from time to time it stops working at all when runnign as a service (installed via NSSM):

~ » curl -v http://dzeta.home:8009/sleep
*   Trying 192.168.113.7:8009...
* Connected to dzeta.home (192.168.113.7) port 8009 (#0)
> GET /sleep HTTP/1.1
> Host: dzeta.home:8009
> User-Agent: curl/7.81.0
> Accept: */*
> 
^C
~ » curl -v http://dzeta.home:8009/sleep
*   Trying 192.168.113.7:8009...
* Connected to dzeta.home (192.168.113.7) port 8009 (#0)
> GET /sleep HTTP/1.1
> Host: dzeta.home:8009
> User-Agent: curl/7.81.0
> Accept: */*
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Date: Sun, 03 Jul 2022 17:40:55 GMT
< Content-Length: 120
< Content-Type: text/xml; charset=utf-8
< 
<?xml version="1.0" encoding="UTF-8"?>
<result>
  <operation>sleep</operation>
  <successful>true</successful>
* Connection #0 to host dzeta.home left intact
</result>%                   

The first case is it's running as a service, the second - running manully in admin-level cmd.
Also wakeonline command with reversed MAC doesn't work in first case as well.

Is there any way to see activity as log (file or windows events) when running as a service?

Split README.md into separated pages

README.md starts to be a bit long : split it into dedicated pages ("How to install SOL as a service", "Developer tasks", "Troublehsooting", ...)

New --verbose parameter

Just about easing debug.
By default log level is INFO.
Log level may be overriden :

  • through JSON configuration (see configuration examples or configuration documentation)
  • through that new --verbose parameter
    The --verbose parameter has a higher priority than what may be configured in JSON file.

No response for HTTP sleep

Hey,

When I call the sleep URL with curl, the curl don't get any response and just hanging. The computer immediately goes into sleep however.

This is causing HomeBridge thinks the command failed.

Could this URL give back a 200 OK blank page or something? This should solve this.

Thanks,
Mark

Shutdown-on-LAN

Hello Serge,

Thank you very much for this great software.

Would it be too much to ask to also add shutdown functionality?
Preferably via config option.

Here is my usage scenario:
I have built a Steam machine based on windows for my kids to play Lego games.
It is connected to Samsung Smart TV which is also connected with ethernet to my home network.
In my home network I use MikroTik as my home router and this router is pretty advanced, it can even do scripting, so with two lines of code I have instructed it to ping my TV's IP and when it detects that it is down (TV off) to send magic packet to MAC address A, and when it detects that the state changed from down to up (TV on) to send magic packet to MAC address B.
Now, this motherboard (Gigabyte GA-Z97N-WIFI) and Intel ethernet chip support wake-on-lan even from shutdown state, which is awesome.
And I would always prefer for the machine to go to shutdown and boot back on when needed, then to go sleep-wake-sleep-wake. Still to this day, for millions of unknown reasons, windows machine runs smoothly only after a fresh boot, while after a week of running dozens of steam games (without any sleep or shutdown) something always goes wrong and the machine runs jerky and slowed down.
So, the only piece I am missing right now is Shutdown-on-LAN.
Using windows' built-in idle timers is impossible as kids will always leave a full screen game on pause and that will prevent any idle detection.

Let me know what do you think about this.

Thanks.

Cheers!

Custom commands don't work in linux

Hi, I'm configuring sleep-on-lan for halt the system and I write this in the sol.json:

{
"Listeners" : ["UDP:9", "UDP:7", "HTTP:8009" ],
"LogLevel" : "INFO",
"Commands" : [
{
"Operation" : "poweroff",
"Command" : "poweroff"
}]
}

I try this configuration and don't work too:
{
"Listeners" : ["UDP:9", "UDP:7", "HTTP:8009" ],
"LogLevel" : "INFO",
"Commands" : [
{
"Operation" : "halt",
"Command" : "pm-halt"
}]
}

The log:
INFO: 2016/12/10 12:18:07 sol.go:19: Now starting sleep-on-lan, hardware IP/mac addresses are :
INFO: 2016/12/10 12:18:07 sol.go:21: - local IP adress [127.0.0.1/8], mac []
INFO: 2016/12/10 12:18:07 sol.go:21: - local IP adress [::1/128], mac []
INFO: 2016/12/10 12:18:07 sol.go:21: - local IP adress [192.168.1.XXX/24], mac [aa:aa:aa:aa:aa:aa]
INFO: 2016/12/10 12:18:07 sol.go:21: - local IP adress [172.17.0.1/16], mac [aa:aa:aa:aa:aa:aa]
INFO: 2016/12/10 12:18:07 listener_udp.go:13: Now listening UDP packets on port [9]
INFO: 2016/12/10 12:18:07 listener_udp.go:13: Now listening UDP packets on port [7]
INFO: 2016/12/10 12:18:07 listener_http.go:126: Now listening HTTP on port [8009], urls will be :
INFO: 2016/12/10 12:18:07 listener_http.go:129: - http://192.168.1.XXX:8009/sleep
INFO: 2016/12/10 12:18:07 listener_http.go:129: - http://192.168.1.XXX:8009/wol/[A-z]+
INFO: 2016/12/10 12:18:07 listener_http.go:129: - http://192.168.1.XXX:8009/

Ther are any problem with json configuration?

Many Thanks

Have extra delay before executing command

A GOLANG "defer" was already in place, but due to the internal GOLANG framework used here for HTTP handlers and depending on the computer being used, HTTP answers could be skipped before sleep being executed.

Hence a new possible configuration :

This is now activated by default with a 500ms value

add commands doesn't work

Hi Serge, Thanks for this usefull application , it works verry good.
but . . . I'll tried to add somme commands, like restart, and it doesn' permite..
config sol.json working good is :
{
"Listeners" : ["UDP:9", "UDP:7", "HTTP:57072" ],
"LogLevel" : "INFO",
"BroadcastIP" : "192.168.1.255",
"ExitIfAnyPortIsAlreadyUsed" : false,
"AvoidDualUDPSending" : {
"Active": true,
"Delay": "100ms"
}
}

I try to add with this but it refuse to start the app, or the service:
{
"Listeners" : ["UDP:9", "UDP:7", "HTTP:57072" ],
"LogLevel" : "INFO",
"BroadcastIP" : "192.168.1.255",
"ExitIfAnyPortIsAlreadyUsed" : false,
"AvoidDualUDPSending" : {
"Active": true,
"Delay": "100ms"
},
"Commands" : [
{
"Operation" : "restart",
"Type" : "external",
"Command" : "C:\Windows\System32\Shutdown.exe /r /f /t 0",
"Default" : "false"
}]
}

can you help me please ?

Thanks a lot , have a nice day

Have better "default configuration" generated

"generate-configuration" options is now a bit more standard.

sol generate-configuration will dump a default configuration on the console
sol --config sol-default.json generate-configuration will dump a default configuration inside the provided configuration filename. Will fail if that filename already exists.

Example :

Example of possible default configuration (to be stored alongside sol binary in a filename like [sol.json])
{
    "Listeners": [
        "UDP:9",
        "HTTP:8009"
    ],
    "LogLevel": "INFO",
    "BroadcastIP": "192.168.255.255",
    "ExitIfAnyPortIsAlreadyUsed": false,
    "Commands": [
        {
            "Operation": "sleep",
            "Command": "systemctl suspend",
            "Default": true,
            "Type": "external"
        }
    ],
    "Auth": {
        "Login": "",
        "Password": ""
    },
    "HTTPOutput": "XML",
    "AvoidDualUDPSending": {
        "Active": false,
        "Delay": "100ms"
    }
}

Also default command is now attached (and updated to "systemctl")

@reb

Works well when run at command line but when trying to use supervisor the server clearly starts as I'm getting a response:
<result> <application>sleep-on-lan</application> <hosts> <host ip="fe80::c23f:d5ff:fea0:94f0/64" mac="c0:3f:d5:a0:94:f0"/> <host ip="10.71.10.6/32" mac=""/> <host ip="127.0.0.1/8" mac=""/> <host ip="::1/128" mac=""/> <host ip="192.168.0.128/24" mac="c0:3f:d5:a0:94:f0"/> <host ip="192.168.11.5/24" mac="c0:3f:d5:a0:94:f0"/> </hosts> <listeners> <listener type="UDP" port="9" active="true"/> <listener type="UDP" port="7" active="true"/> <listener type="HTTP" port="8009" active="true"/> </listeners> </result>

But when calling /sleep/ nothing happens, I just get the same response above. Unlike when I start from the command line, so I'm quite confused. Supervisor conf is as simple as they come:
[program:cat] command=/home/main/SleepOnLAN-1.0.0-SNAPSHOT/linux/sol

PS I'm running debian.

Any Ideas?

Allow HTTP Basic Auth authentification

Optional Basic Auth

{
  "Listeners" : ["UDP:9", "HTTP:8009" ],
  "Auth" : {
      "Login" : "myusername",
      "Password" : "mypassword"
  }
}

New log are :

INFO: 2017/12/20 13:10:27 listener_http.go:92: HTTP starting on port [8009], without auth
... or
INFO: 2017/12/20 13:10:55 listener_http.go:94: HTTP starting on port [8009], with auth activated : login [myusername], password [**********]

Can't run powershell script.

Hi,

I am trying to run powershell script:

	{
		"Operation" : "playvideo",
		"Command" : "powershell.exe -file D:\\hassio\\firefoxOnDesktop.ps1",
		"Default" : false
	}

It works when opening from usual cmd, but not via sleep on lan tool.

Not Found Message for new Commands

I have added a new command to sol.json
The one from the examples: "halt" and "Command" : "C:\Windows\System32\Shutdown.exe -s -t 0"
But I always get a Not found message, doesn't matter which command I try.
Guess is a syntax problem:
ERROR: configuration.go:64: error while loading configuration : invalid character '"' after object key:value pair
What am I doing wrong?

Does it still work on Linux?

Hello! Thank you for your work on this project!

I have tried to run it on Ubuntu Server 18.04, but it does not seem to work. Even logs are empty.
I tries to run it by command from example

sudo setcap 'cap_net_bind_service=+ep' /path/to/sol_binary
nohup /path/to/sol_binary > /var/log/sleep-on-lan.log 2>&1 &

Through ps aux I see that this sol process is running and by tcpdump I see that packets are captured by NIC. But no logs from sol binary are presend and pc is not put into sleep.

Possibly I did something wrong or should I recompile this first if it could help?

Create non-console version, so conhost.exe doesn't also need to run

Thank you for sol, it's working well for my needs. However, being a console app it also spawns a conhost on Windows, even when console output is directed to a file. An additional conhost consumes more memory than both sol and nssm combined, which is rather a shame as in a service configuration we don't need a console anyway.

Would it be possible to compile this as a non-console app as well, so it doesn't generate a conhost?

Many thanks for your work!

4 command executions for 1 sent UDP packet ?

Hi,
First of all thank you for this projet, it's very useful.

When I send 1 "UDP SoL packet" (with Mocha VNC Lite on iPhone), it results (after the log info) with 4 executions of the shutdown command in my case. The server shutdowns correctly but there is a quite annoying issue. If I try to restart the computer immediately (WoL packet), it's shut down again after several seconds.
My guess is the others UDP SoL packets were stuck in some buffer and once the network card is up it is turned off again. Is that possible?
Could it be that I ran the service 4 times and badly killed it? (even after rebooting.. I don't think so)

Log errors are just a user permission issue. This log is the result of 1 UDP SoL packet, is it normal it executes 4 times ?

capture d ecran 2017-12-20 a 11 27 40

Some features you could add:
-A REST "login page" to secure the Sleep on Wan
-A REST page to know the machine state (on/off)

Service fails to start on Windows 10 version 1703

These are the logs from Event Viewer:

Service SleepOnLan received START control, which will be handled.
Started C:\Program Files\SleepOnLAN-1.0.0\windows\sol.exe for service SleepOnLan in C:\Program Files\SleepOnLAN-1.0.0\windows.
Program C:\Program Files\SleepOnLAN-1.0.0\windows\sol.exe for service SleepOnLan exited with return code 3221225794.
Killing process tree of process 8252 for service SleepOnLan with exit code 3221225794
Killing PID 8252 in process tree of PID 8252 because service SleepOnLan is stopping.
Service SleepOnLan action for exit code 3221225794 is Restart. Attempting to restart C:\Program Files\SleepOnLAN-1.0.0\windows\sol.exe.
Service SleepOnLan ran for less than 1500 milliseconds. Restart will be delayed by 2000 milliseconds.

When running from PowerShell it starts normally and functions correctly.

Response not returned before command executed

I am using sol.exe with the Windows sleep command in Example 2.

"Commands" : [ { "Operation" : "sleep", "Command" : "C:\\Windows\\System32\\rundll32.exe powrprof.dll,SetSuspendState 0,1,1" }]

I use a PHP WakeOnLan/SleepOnLan web app on a Raspberry Pi which expects a HTTP response to know if the sleep request was successful or not. The problem I'm seeing is that my computer is going to sleep before the RaspberryPi receives the HTTP response back so the request times out even though sol.exe successfully puts the computer to sleep. Is there any way for the HTTP response to be sent before the sleep command is executed? Thank you.

Extra default filenames

@see documentation in README.md, now configuration may be :

  1. From --config
  2. (linux only) from /etc/sol.json
  3. (linux only) from /etc/sleep-on-lan.json
  4. In a sol.json file located in the same directory than the binary
  5. If no configuration files are found (not configured, not available, ...) then default values are applied

Add a "state" internal command on HTTP connector

If HTTP connector is activated, new routes are published :

INFO: 2017/12/20 18:01:14 listener_http.go:87: Registering route [/state/local]
INFO: 2017/12/20 18:01:14 listener_http.go:87: Registering route [/state/ip/:ip]

Then triggering curl http://localhost:8009/state/ip/192.168.8.222 gives :

INFO: 2017/12/20 18:01:33 listener_http.go:95: Checking state of remote host with IP [192.168.8.222]
INFO: 2017/12/20 18:08:27 listener_http.go:111: Ping results for [192.168.8.222], [5] packets transmitted, [0] packets received, [100.00] packet loss

With the corresponding XML result :

<?xml version="1.0" encoding="UTF-8"?>
<result>
  <state>offline</state>
  <host>192.168.8.222</host>
</result>

And curl http://localhost:8009/state/ip/192.168.8.1 (working IP) or curl http://localhost:8009/state/local gives :

<?xml version="1.0" encoding="UTF-8"?>
<result>
  <state>online</state>
  <host>localhost</host>
</result>

In addition, a "/state/local/online" special HTTP route is available and is just generating a "true|false" result to allow easy parsing.

Moreover, other requests can now be outputed as XML (default, as it was until now) or JSON (through configuration or on a per-request basis, @see README.md)

Make error

It'd seem tensin-app-golang isn't available, do we need your stack, too?

Unable to find image 'tensin-app-golang:latest' locally

image

Sending PC into sleep randomly

I am not 100% sure its the sleep-on-lan script but just curious if anyone has experienced this issue. It could be home-assistant which I am using to control and automate smart devices in my home. When sleep on lan service is (most recently while playing a game) the PC is sent into sleep mode. When I disable it the PC no longer is sent into sleep. I will check my home-assistant logs to see if its sending out a command occasionally. Any idea or ever heard of this happening?

Getting confused with syntax and versions

I have downloaded the 1.0.6 snapshot version here a couple of weeks ago.
But now I don't understand this:
sol.json:

{
  "Listeners" : ["UDP:9", "UDP:7", "HTTP:8009" ],
  "LogLevel" : "INFO",
  "AvoidDualUDPSending" : {
	  "Active": false,
	  "Delay": "100ms"
  }
  "Commands" : [ 
    {
        "Operation" : "hibernate",
        "Command" : "nircmd hibernate",
        "Default" : "true"
    },
    {
        "Operation" : "sleep",
        "Command" : "nircmd sleep",
        "Default" : "false"
    },
    {
        "Operation" : "reboot",
        "Command" : "nircmd exitwin reboot",
        "Default" : "false"
    }]
}

works fine with what presumably is the 1.0.6 Version (11MB filesize, date Oct 17)
If I use it on 1.0.5 only the sleep command would be functional. For the rest I get "not found" errors.

Any explanation for that?
I can't find any syntax issues.

I have to add: If I leave

"AvoidDualUDPSending" : {
	  "Active": false,
	  "Delay": "100ms"
  }

out, it works with 1.0.5
But this section is part of the 1.0.5 sol.json

Windows 10 Run as administrator

Hi

Was testing by just running sol.exe
I thought this application wasn't working.
Tried opening the 8009 port in firewall
Still not working

Then I right clicked, run as adminstrator and it started working.
Maybe should mention this in the documentation?

Thanks for the application, will try it as a service now that I know it is working.

Add internal shutdown command

Per idea by @AtmanActive in fork.

Automatically declared if no configuration file is provided.
Can be re-declared if needed as a command named "shutdown" and type "internal-dll".

A wake up equal a sleep

Hello,

Good work !
A little problem : Each time I wake up the computer (with the mouse or with a WOL packet) it'es interpretated like a sleep request.
How ??? :(
So I can't let your soft running

Custom commands don't work

sol.exe 1.0.1 on windows 7 x64 SP1

I have tried everything, but I simply can't make custom commands work.

If I remove the section '"Commands" : [ { "Operation" : "halt", "Command" :"..." } ]', then going through the REST interface I can issue the 'sleep' command and sol.exe will execute it.

If I add that section, sol.exe does recognize that command by showing information about it in the REST XML output. I also can issue that URL, and sol.exe responds with 'Executing operation [halt]', but nothing happens. Nothing is executed whatsoever.

I have tried with simple notepad.exe, copying it to sol.exe's folder and with relative paths, also with slashes instead of backslashes - nothing.

No go.

Win 32bit ver?

Any chance for 32bit Win version binaries?

I guess i can compile it myself :) but still would be nice to have em here

Fedora 30 not receiving magic packets on UDP

The binary runs fine and it's being run with sudo, I get no errors but doesn't seems to be seeing the mp I'm sending it from my linux laptop. I double checked to see if it wasn't a typo in the reversed mac, but no. Here's the output:

https://pastebin.com/CjCPLa6B

Could it be firewalld blocking the script? I have no knowledge on how to whitelist a binary in it tho. WOL works fine btw.

Incorrect example for Commands?

Hi - I was struggling quite a while to get systemctl suspend to work instead of relying on pm-utils, which is no longer supported on Debian 11.

Then I finally realized I was basing my work on an incorrect example in the docs:

  "Commands" : [ 
    {
        "Operation" : "halt",
        "Command" : "pm-halt",
        "Default" : "false"
    },
    {
        "Operation" : "sleep",
        "Command" : "pm-sleep",
        "Default" : "true"
    }]

Quotes around the value for the attribute Default are incorrect, right?

Here's what failed for me:

{
  "Listeners" : ["UDP:9", "UDP:7", "HTTP:8009" ],
  "LogLevel" : "INFO",
  "ExitIfAnyPortIsAlreadyUsed" : true,
  "AvoidDualUDPSending" : {
          "Active": false,
          "Delay": "100ms"
  },
  "Commands" : [
    {
        "Operation" : "sleep",
        "Command" : "/usr/bin/systemctl suspend",
        "Default" : "false" <<<<======
    }]
}

And here's what worked:

{
  "Listeners" : ["UDP:9", "UDP:7", "HTTP:8009" ],
  "LogLevel" : "INFO",
  "ExitIfAnyPortIsAlreadyUsed" : true,
  "AvoidDualUDPSending" : {
          "Active": false,
          "Delay": "100ms"
  },
  "Commands" : [
    {
        "Operation" : "sleep",
        "Command" : "/usr/bin/systemctl suspend",
        "Default" : false <<<<======
    }]
}

Excellent utility by the way, thanks for putting it out there!

Confirmation Dialog

Awesome program. A really useful feature would be to display a confirmation dialog on the computer that was being put to sleep so that a user wouldn't be unexpectedly get locked out. I could imagine opening a dialog window on computer that timed out after 30 seconds allowing the user to cancel the sleep request. Thanks!

Can't make UDP WOL packet work on windows

sol.exe 1.0.1 on windows 7 x64 SP1

So, my Mikrotik is sending these:

ON:  tool wol interface=LAN mac=FC:AA:14:2B:58:EA
OFF: tool wol interface=LAN mac=EA:58:2B:14:AA:FC

sol.json: default as stated here: https://github.com/SR-G/sleep-on-lan

My machine wakes up alright, but sol.exe won't put it to sleep.
If I try the same thing via REST interface, then, yes it does work.

For now, I am using the workaround where my MikroTik can send REST commands as well, so I just added:
OFF: tool fetch url="http://192.168.173.18:8009/sleep" mode=http

and now it does sleep as intended.
But this is a workaround, not an intended behavior.

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.