summaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorSimon Rettberg2022-05-24 14:11:30 +0200
committerSimon Rettberg2022-05-24 14:11:30 +0200
commitf354eac3fadfa2317ac26a6b8d86f6d43ba3fab5 (patch)
treef89a2b54d78b8bc9824816479b469f18223b1ec5 /src/main
parent[CompileIPxeNew] Copy bwlp config into ipxe src (diff)
downloadtmlite-bwlp-f354eac3fadfa2317ac26a6b8d86f6d43ba3fab5.tar.gz
tmlite-bwlp-f354eac3fadfa2317ac26a6b8d86f6d43ba3fab5.tar.xz
tmlite-bwlp-f354eac3fadfa2317ac26a6b8d86f6d43ba3fab5.zip
[WakeOnLan] Implement password usage as it's actually required :>
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/openslx/taskmanager/tasks/WakeOnLan.java16
1 files 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<String, ArrayList<String>> 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<String> list = byMethod.get( method );
if ( list == null ) {
list = new ArrayList<>();
@@ -104,12 +107,13 @@ public class WakeOnLan extends AbstractTask
final List<String> 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<String> methods;
/**
- * WOL password (currently unused by slx-admin)
+ * WOL password
*/
@Expose
private String password;