guacamole-server icon indicating copy to clipboard operation
guacamole-server copied to clipboard

GUACAMOLE-1686: Make WOL functionality capable of testing connectivity to the server.

Open necouchman opened this issue 1 year ago • 5 comments

This PR adds to the Wake-on-LAN functionality, implementing a new function that checks the connection to the destination server both before sending the WOL packet and, again, after sending the packet. If the host responds before sending the WOL packet, there is no need to actually send the WOL packet. If the packet does get sent, then the function will attempt to connect, then wait for the specified time period and then re-try the connection.

As a by-product of this implementation, I've also added a couple of other things:

  • Centralized the TCP socket connection functionality into a common function, and updated the protocols that use it (SSH and Telnet, at the moment) to use that function. I'm not sure I got this in the right place, so if there are opinions about where to move it, I'm happy to adjust.
  • Implemented a shared function to convert an integer to a string.

necouchman avatar Dec 28 '23 19:12 necouchman

Thanks for the PR. I gave it a try after merging it with master but can't seem to get my VNC connection to work as designed.

It seems as though the guacd thread stops immediately after sending the WoL packet, possibly after calling guac_wol_wake_and_wait. This is what I see in the debug logs:

guacd[216]: INFO:       User "@129a3167-dfc7-4826-80cd-89b938108cd8" joined connection "$9068079c-9de1-4f0c-b29e-f8651ba25cf1" (1 users now present)
guacd[216]: DEBUG:      Sending Wake-on-LAN packet, and pausing for 2 seconds.
guacd[216]: DEBUG:      Client is using protocol version "VERSION_1_5_0"
guacd[1]: INFO: Connection "$9068079c-9de1-4f0c-b29e-f8651ba25cf1" removed.
guacd[1]: DEBUG:        Unable to request termination of client process: No such process
guacd[1]: DEBUG:        All child processes for connection "$9068079c-9de1-4f0c-b29e-f8651ba25cf1" have been terminated.

If I set wol-wake-time to 0 which (which bypasses the call to guac_wol_wake_and_wait), the VNC connection works once the machine comes up.

kohrar avatar Mar 15 '24 18:03 kohrar

Just a quick update -- the segfault comes from str_port being uninitialized before getting passed to guac_itoa. After fixing that (I just hard coded a malloc of 6 bytes to it) and it seems to be working OK.

kohrar avatar Mar 18 '24 22:03 kohrar

Thanks, @kohrar! I suspect that after I converted the guac_itoa() function to not do the allocation itself I forgot to go back and allocate. I'll fix this up...

necouchman avatar Mar 18 '24 22:03 necouchman

Just a quick update -- the segfault comes from str_port being uninitialized before getting passed to guac_itoa. After fixing that (I just hard coded a malloc of 6 bytes to it) and it seems to be working OK.

Apparently I had already fixed this in my git code, but not pushed it :facepalm:. Should be fixed, now.

necouchman avatar Mar 25 '24 21:03 necouchman

For RDP connection "guac_socket_tcp_connect" don't work. Function "guac_wol_wake_and_wait" allways wait "wait_time" seconds.

I found error. Function guac_itoa for port number "3389" return 338.

Correct text for guac_itoa:

int guac_itoa(char* restrict dest, unsigned int integer) {

/* Determine size of string. */
int str_size = snprintf(dest, 0, "%u", integer) + 1;

/* Do the conversion and return. */
return snprintf(dest, str_size, "%u", integer);

}

NickVStepin avatar Apr 04 '24 13:04 NickVStepin

@jmuehlner Any further changes that need to be made on this one?

necouchman avatar May 22 '24 02:05 necouchman

I don't have any other changes.

С наилучшими пожеланиями,

Николай В.Степин

Директор информационной службы

ООО "Декор"

http://www.evroplast.ru/ www.evroplast.ru

@.> @.

+7(495) 789-6270 д.3108

Post hoc, non est propter hoc.

From: Virtually Nick @.*** Sent: Wednesday, May 22, 2024 5:01 AM To: apache/guacamole-server Cc: NickVStepin; Comment Subject: Re: [apache/guacamole-server] GUACAMOLE-1686: Make WOL functionality capable of testing connectivity to the server. (PR #470)

@jmuehlner https://github.com/jmuehlner Any further changes that need to be made on this one?

— Reply to this email directly, view it on GitHub https://github.com/apache/guacamole-server/pull/470#issuecomment-2123734497 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AMQZH7YYYEP33K3QPH7H26DZDP37LAVCNFSM6AAAAABBF2OEDKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMRTG4ZTINBZG4 . You are receiving this because you commented. https://github.com/notifications/beacon/AMQZH725DCTIGQ3UVFFED7DZDP37LA5CNFSM6AAAAABBF2OEDKWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTT6SWO6C.gif Message ID: @.***>

NickVStepin avatar May 22 '24 07:05 NickVStepin

@jmuehlner Any further changes that need to be made on this one?

Nope, looks reasonable to me.

jmuehlner avatar May 22 '24 16:05 jmuehlner