Skip to content

Commit

Permalink
GUACAMOLE-1686: Update WOL for all protocols to use guac_wake_and_wait.
Browse files Browse the repository at this point in the history
  • Loading branch information
necouchman committed Jan 12, 2024
1 parent d4a2339 commit 8e2c677
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 39 deletions.
52 changes: 41 additions & 11 deletions src/protocols/rdp/rdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
#include <guacamole/socket.h>
#include <guacamole/string.h>
#include <guacamole/timestamp.h>
#include <guacamole/wol-constants.h>
#include <guacamole/wol.h>
#include <winpr/error.h>
#include <winpr/synch.h>
Expand Down Expand Up @@ -681,19 +682,48 @@ void* guac_rdp_client_thread(void* data) {
guac_rdp_client* rdp_client = (guac_rdp_client*) client->data;
guac_rdp_settings* settings = rdp_client->settings;

/* If Wake-on-LAN is enabled, try to wake. */
/* If Wake-on-LAN is enabled, attempt to wake. */
if (settings->wol_send_packet) {
guac_client_log(client, GUAC_LOG_DEBUG, "Sending Wake-on-LAN packet, "
"and pausing for %d seconds.", settings->wol_wait_time);

/* Send the Wake-on-LAN request. */
if (guac_wol_wake(settings->wol_mac_addr, settings->wol_broadcast_addr,
settings->wol_udp_port))

/**
* If wait time is set, send the wake packet and try to connect to the
* server, failing if the server does not respond.
*/
if (settings->wol_wait_time > 0) {
guac_client_log(client, GUAC_LOG_DEBUG, "Sending Wake-on-LAN packet, "
"and pausing for %d seconds.", settings->wol_wait_time);

char* str_port = NULL;
if (guac_itoa(str_port, settings->port) < 1) {
guac_client_log(client, GUAC_LOG_ERROR, "Failed to convert port to integer for WOL function.");
guac_mem_free(str_port);
return NULL;
}

/* Send the Wake-on-LAN request and wait until the server is responsive. */
if (guac_wol_wake_and_wait(settings->wol_mac_addr,
settings->wol_broadcast_addr,
settings->wol_udp_port,
settings->wol_wait_time,
GUAC_WOL_DEFAULT_CONNECT_RETRIES,
settings->hostname,
(const char *) str_port)) {
guac_client_log(client, GUAC_LOG_ERROR, "Failed to send WOL packet, or server failed to wake up.");
guac_mem_free(str_port);
return NULL;
}

guac_mem_free(str_port);

}

/* Just send the packet and continue the connection, or return if failed. */
else if(guac_wol_wake(settings->wol_mac_addr,
settings->wol_broadcast_addr,
settings->wol_udp_port)) {
guac_client_log(client, GUAC_LOG_ERROR, "Failed to send WOL packet.");
return NULL;

/* If wait time is specified, sleep for that amount of time. */
if (settings->wol_wait_time > 0)
guac_timestamp_msleep(settings->wol_wait_time * 1000);
}
}

/* If audio enabled, choose an encoder */
Expand Down
37 changes: 28 additions & 9 deletions src/protocols/ssh/ssh.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <guacamole/recording.h>
#include <guacamole/socket.h>
#include <guacamole/timestamp.h>
#include <guacamole/wol-constants.h>
#include <guacamole/wol.h>
#include <openssl/err.h>
#include <openssl/ssl.h>
Expand Down Expand Up @@ -233,17 +234,35 @@ void* ssh_client_thread(void* data) {

/* If Wake-on-LAN is enabled, attempt to wake. */
if (settings->wol_send_packet) {
guac_client_log(client, GUAC_LOG_DEBUG, "Sending Wake-on-LAN packet, "
"and pausing for %d seconds.", settings->wol_wait_time);

/* Send the Wake-on-LAN request. */
if (guac_wol_wake(settings->wol_mac_addr, settings->wol_broadcast_addr,
settings->wol_udp_port))
return NULL;
/**
* If wait time is set, send the wake packet and try to connect to the
* server, failing if the server does not respond.
*/
if (settings->wol_wait_time > 0) {
guac_client_log(client, GUAC_LOG_DEBUG, "Sending Wake-on-LAN packet, "
"and pausing for %d seconds.", settings->wol_wait_time);

/* Send the Wake-on-LAN request and wait until the server is responsive. */
if (guac_wol_wake_and_wait(settings->wol_mac_addr,
settings->wol_broadcast_addr,
settings->wol_udp_port,
settings->wol_wait_time,
GUAC_WOL_DEFAULT_CONNECT_RETRIES,
settings->hostname,
settings->port)) {
guac_client_log(client, GUAC_LOG_ERROR, "Failed to send WOL packet or connect to remote server.");
return NULL;
}
}

/* If wait time is specified, sleep for that amount of time. */
if (settings->wol_wait_time > 0)
guac_timestamp_msleep(settings->wol_wait_time * 1000);
/* Just send the packet and continue the connection, or return if failed. */
else if(guac_wol_wake(settings->wol_mac_addr,
settings->wol_broadcast_addr,
settings->wol_udp_port)) {
guac_client_log(client, GUAC_LOG_ERROR, "Failed to send WOL packet.");
return NULL;
}
}

/* Init SSH base libraries */
Expand Down
37 changes: 28 additions & 9 deletions src/protocols/telnet/telnet.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <guacamole/recording.h>
#include <guacamole/socket-tcp.h>
#include <guacamole/timestamp.h>
#include <guacamole/wol-constants.h>
#include <guacamole/wol.h>
#include <libtelnet.h>

Expand Down Expand Up @@ -494,17 +495,35 @@ void* guac_telnet_client_thread(void* data) {

/* If Wake-on-LAN is enabled, attempt to wake. */
if (settings->wol_send_packet) {
guac_client_log(client, GUAC_LOG_DEBUG, "Sending Wake-on-LAN packet, "
"and pausing for %d seconds.", settings->wol_wait_time);

/* Send the Wake-on-LAN request. */
if (guac_wol_wake(settings->wol_mac_addr, settings->wol_broadcast_addr,
settings->wol_udp_port))
return NULL;
/**
* If wait time is set, send the wake packet and try to connect to the
* server, failing if the server does not respond.
*/
if (settings->wol_wait_time > 0) {
guac_client_log(client, GUAC_LOG_DEBUG, "Sending Wake-on-LAN packet, "
"and pausing for %d seconds.", settings->wol_wait_time);

/* Send the Wake-on-LAN request and wait until the server is responsive. */
if (guac_wol_wake_and_wait(settings->wol_mac_addr,
settings->wol_broadcast_addr,
settings->wol_udp_port,
settings->wol_wait_time,
GUAC_WOL_DEFAULT_CONNECT_RETRIES,
settings->hostname,
settings->port)) {
guac_client_log(client, GUAC_LOG_ERROR, "Failed to send WOL packet or connect to remote server.");
return NULL;
}
}

/* If wait time is specified, sleep for that amount of time. */
if (settings->wol_wait_time > 0)
guac_timestamp_msleep(settings->wol_wait_time * 1000);
/* Just send the packet and continue the connection, or return if failed. */
else if(guac_wol_wake(settings->wol_mac_addr,
settings->wol_broadcast_addr,
settings->wol_udp_port)) {
guac_client_log(client, GUAC_LOG_ERROR, "Failed to send WOL packet.");
return NULL;
}
}

/* Set up screen recording, if requested */
Expand Down
52 changes: 42 additions & 10 deletions src/protocols/vnc/vnc.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,13 @@
#endif

#include <guacamole/client.h>
#include <guacamole/mem.h>
#include <guacamole/protocol.h>
#include <guacamole/recording.h>
#include <guacamole/socket.h>
#include <guacamole/string.h>
#include <guacamole/timestamp.h>
#include <guacamole/wol-constants.h>
#include <guacamole/wol.h>
#include <rfb/rfbclient.h>
#include <rfb/rfbconfig.h>
Expand Down Expand Up @@ -274,17 +277,46 @@ void* guac_vnc_client_thread(void* data) {

/* If Wake-on-LAN is enabled, attempt to wake. */
if (settings->wol_send_packet) {
guac_client_log(client, GUAC_LOG_DEBUG, "Sending Wake-on-LAN packet, "
"and pausing for %d seconds.", settings->wol_wait_time);

/* Send the Wake-on-LAN request. */
if (guac_wol_wake(settings->wol_mac_addr, settings->wol_broadcast_addr,
settings->wol_udp_port))

/**
* If wait time is set, send the wake packet and try to connect to the
* server, failing if the server does not respond.
*/
if (settings->wol_wait_time > 0) {
guac_client_log(client, GUAC_LOG_DEBUG, "Sending Wake-on-LAN packet, "
"and pausing for %d seconds.", settings->wol_wait_time);

char* str_port = NULL;
if (guac_itoa(str_port, settings->port) < 1) {
guac_client_log(client, GUAC_LOG_ERROR, "Failed to convert port to integer for WOL function.");
guac_mem_free(str_port);
return NULL;
}

/* Send the Wake-on-LAN request and wait until the server is responsive. */
if (guac_wol_wake_and_wait(settings->wol_mac_addr,
settings->wol_broadcast_addr,
settings->wol_udp_port,
settings->wol_wait_time,
GUAC_WOL_DEFAULT_CONNECT_RETRIES,
settings->hostname,
(const char *) str_port)) {
guac_client_log(client, GUAC_LOG_ERROR, "Failed to send WOL packet or connect to remote system.");
guac_mem_free(str_port);
return NULL;
}

guac_mem_free(str_port);

}

/* Just send the packet and continue the connection, or return if failed. */
else if(guac_wol_wake(settings->wol_mac_addr,
settings->wol_broadcast_addr,
settings->wol_udp_port)) {
guac_client_log(client, GUAC_LOG_ERROR, "Failed to send WOL packet.");
return NULL;

/* If wait time is specified, sleep for that amount of time. */
if (settings->wol_wait_time > 0)
guac_timestamp_msleep(settings->wol_wait_time * 1000);
}
}

/* Configure clipboard encoding */
Expand Down

0 comments on commit 8e2c677

Please sign in to comment.