From f354eac3fadfa2317ac26a6b8d86f6d43ba3fab5 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 24 May 2022 14:11:30 +0200 Subject: [WakeOnLan] Implement password usage as it's actually required :> --- .../java/org/openslx/taskmanager/tasks/WakeOnLan.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/openslx/taskmanager/tasks/WakeOnLan.java b/src/main/java/org/openslx/taskmanager/tasks/WakeOnLan.java index 7a4a58e..c03740a 100644 --- a/src/main/java/org/openslx/taskmanager/tasks/WakeOnLan.java +++ b/src/main/java/org/openslx/taskmanager/tasks/WakeOnLan.java @@ -66,6 +66,9 @@ public class WakeOnLan extends AbstractTask status.addMsg( "Clients empty" ); } } + if ( ssh == null ) { + ssh = new HashMap<>( 1 ); + } if ( !Util.isEmpty( status.messages ) ) return false; return true; @@ -75,7 +78,7 @@ public class WakeOnLan extends AbstractTask protected boolean execute() { // Loop over clients until they all were handled (i.e. methods is empty) - ExecutorService tp = Executors.newFixedThreadPool( ssh.size() > 4 ? 4 : ssh.size() ); + ExecutorService tp = Executors.newFixedThreadPool( Math.max( 1, Math.min( 4, ssh.size() ) ) ); Map> byMethod; int jobIdCounter = 0; do { @@ -85,7 +88,7 @@ public class WakeOnLan extends AbstractTask if ( client.methods.isEmpty() ) continue; // Group by method and destination IP address - String method = client.methods.remove( 0 ) + "//" + client.ip; + String method = client.methods.remove( 0 ) + "//" + client.ip + "//" + ( client.password == null ? "" : client.password ); ArrayList list = byMethod.get( method ); if ( list == null ) { list = new ArrayList<>(); @@ -104,12 +107,13 @@ public class WakeOnLan extends AbstractTask final List macs = it.getValue(); final String macString = Strings.join( macs.iterator(), ' ' ); final String broadcastIp = parts[1]; + final String password = parts[2]; final int jobId = ++jobIdCounter; if ( method.equalsIgnoreCase( "DIRECT" ) ) { // Directly from server waitList.add( tp.submit( () -> { status.addMsg( jobId + ": Waking directly from server: " + macString ); - WakeOnLanExecutor wol = new WakeOnLanExecutor( null ); + WakeOnLanExecutor wol = new WakeOnLanExecutor( password ); String[] success = wol.execute( status, macs, broadcastIp, this.port ); markSuccess( Arrays.asList( success ) ); if ( success.length == macs.size() ) { @@ -123,7 +127,9 @@ public class WakeOnLan extends AbstractTask waitList.add( tp.submit( () -> { SshData sshData = this.ssh.get( method ); status.addMsg( jobId + ": Waking via SSH from " + sshData.ip + " to " + broadcastIp + ": " + macString ); - String command = sshData.command.replace( "%MACS%", macString ).replace( "%IP%", broadcastIp ); + String command = sshData.command.replace( "%MACS%", macString ) + .replace( "%IP%", broadcastIp ) + .replace( "%PASSWORD%", password ); RemoteExec.Client c = new RemoteExec.Client( null, sshData.ip, sshData.port, sshData.username ); RemoteExec task = new RemoteExec( new RemoteExec.Client[] { c }, sshData.sshkey, sshData.port, command, 5 ); task.execute(); @@ -209,7 +215,7 @@ public class WakeOnLan extends AbstractTask @Expose List methods; /** - * WOL password (currently unused by slx-admin) + * WOL password */ @Expose private String password; -- cgit v1.2.3-55-g7522