blob: 36ec7d6bdfe80d30ff18a23b7aabcf30d064cc47 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
package org.openslx.taskmanager.tasks;
import java.util.Arrays;
import org.openslx.satserver.util.Exec;
import org.openslx.satserver.util.Exec.ExecCallback;
import org.openslx.satserver.util.Util;
import org.openslx.taskmanager.api.AbstractTask;
import com.google.gson.annotations.Expose;
public class WakeOnLan extends AbstractTask implements ExecCallback
{
@Expose
private String[] macs;
@Expose
private String ip;
@Expose
private String password;
private String[] cmdline;
private StatusObject status;
@Override
protected boolean initTask()
{
status = new StatusObject();
this.setStatusObject( status );
if ( macs == null || macs.length == 0 ) {
status.addMsg( "Macs empty" );
}
if ( Util.isEmpty( ip ) ) {
status.addMsg( "IP empty" );
}
if ( !Util.isEmpty( status.messages ) )
return false;
int xlen = Util.isEmpty( password ) ? 0 : 2;
cmdline = new String[macs.length + 3 + xlen];
cmdline[0] = "jawol";
cmdline[1] = "-d";
cmdline[2] = ip;
if ( xlen != 0 ) {
cmdline[3] = "-p";
cmdline[4] = password;
}
System.arraycopy( macs, 0, cmdline, 3 + xlen, macs.length );
status.addMsg( "Command line: " + Arrays.toString( cmdline ) );
return true;
}
@Override
protected boolean execute()
{
int ret;
for ( int i = 0; i < 2; ++i ) {
ret = Exec.sync( 1, this, cmdline );
if ( ret != 0 )
return false;
try {
Thread.sleep( 800 );
} catch ( InterruptedException e ) {
}
}
return Exec.sync( 1, cmdline ) == 0;
}
@Override
public void processStdOut( String line )
{
status.addMsg( line );
}
@Override
public void processStdErr( String line )
{
status.addMsg( line );
}
class StatusObject
{
private String messages = "";
public void addMsg( String str )
{
messages = messages + "\n" + str;
}
}
}
|