Subversion Repositories XServices

Rev

Rev 70 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 70 Rev 177
1
/*
1
/*
2
 *   Copyright 2010 Brian Rosenberger (Brutex Network)
2
 *   Copyright 2010 Brian Rosenberger (Brutex Network)
3
 *
3
 *
4
 *   Licensed under the Apache License, Version 2.0 (the "License");
4
 *   Licensed under the Apache License, Version 2.0 (the "License");
5
 *   you may not use this file except in compliance with the License.
5
 *   you may not use this file except in compliance with the License.
6
 *   You may obtain a copy of the License at
6
 *   You may obtain a copy of the License at
7
 *
7
 *
8
 *       http://www.apache.org/licenses/LICENSE-2.0
8
 *       http://www.apache.org/licenses/LICENSE-2.0
9
 *
9
 *
10
 *   Unless required by applicable law or agreed to in writing, software
10
 *   Unless required by applicable law or agreed to in writing, software
11
 *   distributed under the License is distributed on an "AS IS" BASIS,
11
 *   distributed under the License is distributed on an "AS IS" BASIS,
12
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 *   See the License for the specific language governing permissions and
13
 *   See the License for the specific language governing permissions and
14
 *   limitations under the License.
14
 *   limitations under the License.
15
 */
15
 */
16
 
16
 
17
package net.brutex.xservices.ws.impl;
17
package net.brutex.xservices.ws.impl;
18
 
18
 
19
import java.io.File;
19
import java.io.File;
20
import java.util.UUID;
-
 
21
 
-
 
22
import javax.jws.WebMethod;
20
import javax.jws.WebMethod;
23
import javax.jws.WebParam;
21
import javax.jws.WebParam;
24
import javax.jws.WebService;
22
import javax.jws.WebService;
25
import net.brutex.xservices.types.HostConnection;
23
import net.brutex.xservices.types.HostConnection;
26
import net.brutex.xservices.types.ReturnCode;
24
import net.brutex.xservices.types.ReturnCode;
27
import net.brutex.xservices.util.BrutexNamespaces;
25
import net.brutex.xservices.util.BrutexNamespaces;
28
import net.brutex.xservices.util.JobWrapper;
-
 
29
import net.brutex.xservices.util.RunTask;
26
import net.brutex.xservices.util.RunTask;
30
import net.brutex.xservices.ws.ExecuteService;
27
import net.brutex.xservices.ws.ExecuteService;
31
import net.brutex.xservices.ws.XServicesFault;
28
import net.brutex.xservices.ws.XServicesFault;
32
 
29
 
33
import org.apache.tools.ant.taskdefs.ExecTask;
30
import org.apache.tools.ant.taskdefs.ExecTask;
34
import org.apache.tools.ant.taskdefs.optional.net.RExecTask;
31
import org.apache.tools.ant.taskdefs.optional.net.RExecTask;
35
import org.apache.tools.ant.taskdefs.optional.net.TelnetTask;
32
import org.apache.tools.ant.taskdefs.optional.net.TelnetTask;
36
import org.apache.tools.ant.taskdefs.optional.ssh.SSHExec;
33
import org.apache.tools.ant.taskdefs.optional.ssh.SSHExec;
37
import org.apache.tools.ant.types.Commandline;
34
import org.apache.tools.ant.types.Commandline;
38
import org.mozilla.javascript.Context;
35
import org.mozilla.javascript.Context;
39
import org.mozilla.javascript.Scriptable;
36
import org.mozilla.javascript.Scriptable;
40
import org.quartz.JobBuilder;
-
 
41
import org.quartz.JobDetail;
-
 
42
import org.quartz.Scheduler;
-
 
43
import org.quartz.SchedulerException;
-
 
44
import org.quartz.Trigger;
-
 
45
import static org.quartz.TriggerBuilder.*;
-
 
46
import static org.quartz.SimpleScheduleBuilder.*;
-
 
47
import org.quartz.TriggerUtils;
-
 
48
import org.quartz.impl.StdSchedulerFactory;
-
 
49
import org.quartz.impl.triggers.SimpleTriggerImpl;
-
 
50
 
37
 
51
/**
38
/**
52
 * 
39
 * 
53
 * @author Brian Rosenberger, bru@brutex.de
40
 * @author Brian Rosenberger, bru@brutex.de
54
 */
41
 */
55
@WebService(targetNamespace = BrutexNamespaces.WS_XSERVICES, endpointInterface = "net.brutex.xservices.ws.ExecuteService", serviceName = "ExecuteService")
42
@WebService(targetNamespace = BrutexNamespaces.WS_XSERVICES, endpointInterface = "net.brutex.xservices.ws.ExecuteService", serviceName = "ExecuteService")
56
public class ExecuteServiceImpl implements ExecuteService {
43
public class ExecuteServiceImpl implements ExecuteService {
57
 
44
 
58
	/*
45
	/*
59
	 * (non-Javadoc)
46
	 * (non-Javadoc)
60
	 * 
47
	 * 
61
	 * @see
48
	 * @see
62
	 * net.brutex.xservices.ws.impl.ExecuteService#runCommand(java.lang.String,
49
	 * net.brutex.xservices.ws.impl.ExecuteService#runCommand(java.lang.String,
63
	 * java.lang.String, long)
50
	 * java.lang.String, long)
64
	 */
51
	 */
65
	@WebMethod(operationName = "runCommand")
52
	@WebMethod(operationName = "runCommand")
66
	public ReturnCode runCommand(@WebParam(name = "executable") String cmd,
53
	public ReturnCode runCommand(@WebParam(name = "executable") String cmd,
67
			@WebParam(name = "argline") String args,
54
			@WebParam(name = "argline") String args,
68
			@WebParam(name = "timeout") long timeout) {
55
			@WebParam(name = "timeout") long timeout) {
69
 
56
 
70
		return executeCommand(cmd, Commandline.translateCommandline(args),
57
		return executeCommand(cmd, Commandline.translateCommandline(args),
71
				null, false, null, false, true, false, timeout);
58
				null, false, null, false, true, false, timeout);
72
	}
59
	}
73
 
60
 
74
	/*
61
	/*
75
	 * (non-Javadoc)
62
	 * (non-Javadoc)
76
	 * 
63
	 * 
77
	 * @see
64
	 * @see
78
	 * net.brutex.xservices.ws.impl.ExecuteService#runCommandWithArgs(java.lang
65
	 * net.brutex.xservices.ws.impl.ExecuteService#runCommandWithArgs(java.lang
79
	 * .String, java.lang.String[], long)
66
	 * .String, java.lang.String[], long)
80
	 */
67
	 */
81
	
68
	
82
	@WebMethod(operationName = "runCommandWithArgs")
69
	@WebMethod(operationName = "runCommandWithArgs")
83
	public ReturnCode runCommandWithArgs(
70
	public ReturnCode runCommandWithArgs(
84
			@WebParam(name = "executable") String cmd,
71
			@WebParam(name = "executable") String cmd,
85
			@WebParam(name = "arg") String[] args,
72
			@WebParam(name = "arg") String[] args,
86
			@WebParam(name = "timeout") long timeout) {
73
			@WebParam(name = "timeout") long timeout) {
87
 
74
 
88
		return executeCommand(cmd, args, null, false, null, false, true, false,
75
		return executeCommand(cmd, args, null, false, null, false, true, false,
89
				timeout);
76
				timeout);
90
	}
77
	}
91
 
78
 
92
	/*
79
	/*
93
	 * (non-Javadoc)
80
	 * (non-Javadoc)
94
	 * 
81
	 * 
95
	 * @see
82
	 * @see
96
	 * net.brutex.xservices.ws.impl.ExecuteService#runCommandAsync(java.lang
83
	 * net.brutex.xservices.ws.impl.ExecuteService#runCommandAsync(java.lang
97
	 * .String, java.lang.String)
84
	 * .String, java.lang.String)
98
	 */
85
	 */
99
	
86
	
100
	@WebMethod(operationName = "runCommandAsync")
87
	@WebMethod(operationName = "runCommandAsync")
101
	public ReturnCode runCommandAsync(
88
	public ReturnCode runCommandAsync(
102
			@WebParam(name = "executable") String cmd,
89
			@WebParam(name = "executable") String cmd,
103
			@WebParam(name = "argline") String args) {
90
			@WebParam(name = "argline") String args) {
104
 
91
 
105
		return executeCommand(cmd, Commandline.translateCommandline(args),
92
		return executeCommand(cmd, Commandline.translateCommandline(args),
106
				null, true, null, false, true, false, 0);
93
				null, true, null, false, true, false, 0);
107
	}
94
	}
108
 
95
 
109
	/*
96
	/*
110
	 * (non-Javadoc)
97
	 * (non-Javadoc)
111
	 * 
98
	 * 
112
	 * @see
99
	 * @see
113
	 * net.brutex.xservices.ws.impl.ExecuteService#runCommandAsyncWithArgs(java
100
	 * net.brutex.xservices.ws.impl.ExecuteService#runCommandAsyncWithArgs(java
114
	 * .lang.String, java.lang.String[])
101
	 * .lang.String, java.lang.String[])
115
	 */
102
	 */
116
	
103
	
117
	@WebMethod(operationName = "runCommandAsyncWithArgs")
104
	@WebMethod(operationName = "runCommandAsyncWithArgs")
118
	public ReturnCode runCommandAsyncWithArgs(
105
	public ReturnCode runCommandAsyncWithArgs(
119
			@WebParam(name = "executable") String cmd,
106
			@WebParam(name = "executable") String cmd,
120
			@WebParam(name = "arg") String[] args) {
107
			@WebParam(name = "arg") String[] args) {
121
 
108
 
122
		return executeCommand(cmd, args, null, true, null, false, true, false,
109
		return executeCommand(cmd, args, null, true, null, false, true, false,
123
				0);
110
				0);
124
	}
111
	}
125
 
112
 
126
	/*
113
	/*
127
	 * (non-Javadoc)
114
	 * (non-Javadoc)
128
	 * 
115
	 * 
129
	 * @see
116
	 * @see
130
	 * net.brutex.xservices.ws.impl.ExecuteService#runCommandWithSSH(java.lang
117
	 * net.brutex.xservices.ws.impl.ExecuteService#runCommandWithSSH(java.lang
131
	 * .String, int, java.lang.String, java.lang.String, java.lang.String, long)
118
	 * .String, int, java.lang.String, java.lang.String, java.lang.String, long)
132
	 */
119
	 */
133
	
120
	
134
	@WebMethod(operationName = "runCommandWithSSH")
121
	@WebMethod(operationName = "runCommandWithSSH")
135
	public ReturnCode runCommandWithSSH(
122
	public ReturnCode runCommandWithSSH(
136
			@WebParam(name = "host") HostConnection host,
123
			@WebParam(name = "host") HostConnection host,
137
			@WebParam(name = "command") String cmd,
124
			@WebParam(name = "command") String cmd,
138
			@WebParam(name = "timeout") long timeout) {
125
			@WebParam(name = "timeout") long timeout) {
139
 
126
 
140
		return sshExec(host.hostname, host.user, host.password, host.port, cmd,
127
		return sshExec(host.hostname, host.user, host.password, host.port, cmd,
141
				timeout);
128
				timeout);
142
	}
129
	}
143
 
130
 
144
	/*
131
	/*
145
	 * (non-Javadoc)
132
	 * (non-Javadoc)
146
	 * 
133
	 * 
147
	 * @see
134
	 * @see
148
	 * net.brutex.xservices.ws.impl.ExecuteService#runCommandWithSSHKeyAuth(
135
	 * net.brutex.xservices.ws.impl.ExecuteService#runCommandWithSSHKeyAuth(
149
	 * java.lang.String, int, java.lang.String, java.lang.String,
136
	 * java.lang.String, int, java.lang.String, java.lang.String,
150
	 * java.lang.String, java.lang.String, long)
137
	 * java.lang.String, java.lang.String, long)
151
	 */
138
	 */
152
	
139
	
153
	@WebMethod(operationName = "runCommandWithSSHKeyAuth")
140
	@WebMethod(operationName = "runCommandWithSSHKeyAuth")
154
	public ReturnCode runCommandWithSSHKeyAuth(
141
	public ReturnCode runCommandWithSSHKeyAuth(
155
			@WebParam(name = "host") HostConnection host,
142
			@WebParam(name = "host") HostConnection host,
156
			@WebParam(name = "keyfile") String keyfile,
143
			@WebParam(name = "keyfile") String keyfile,
157
			@WebParam(name = "command") String cmd,
144
			@WebParam(name = "command") String cmd,
158
			@WebParam(name = "timeout") long timeout) {
145
			@WebParam(name = "timeout") long timeout) {
159
 
146
 
160
		return sshExecWithCert(host.hostname, host.user, host.password,
147
		return sshExecWithCert(host.hostname, host.user, host.password,
161
				keyfile, host.port, cmd, timeout);
148
				keyfile, host.port, cmd, timeout);
162
	}
149
	}
163
 
150
 
164
	/*
151
	/*
165
	 * (non-Javadoc)
152
	 * (non-Javadoc)
166
	 * 
153
	 * 
167
	 * @see
154
	 * @see
168
	 * net.brutex.xservices.ws.impl.ExecuteService#rExec(net.brutex.xservices
155
	 * net.brutex.xservices.ws.impl.ExecuteService#rExec(net.brutex.xservices
169
	 * .types.HostConnection, java.lang.String, long)
156
	 * .types.HostConnection, java.lang.String, long)
170
	 */
157
	 */
171
	
158
	
172
	@WebMethod(operationName = "rExec")
159
	@WebMethod(operationName = "rExec")
173
	public ReturnCode rExec(@WebParam(name = "host") HostConnection host,
160
	public ReturnCode rExec(@WebParam(name = "host") HostConnection host,
174
			@WebParam(name = "command") String cmd,
161
			@WebParam(name = "command") String cmd,
175
			@WebParam(name = "timeout") long timeout) {
162
			@WebParam(name = "timeout") long timeout) {
176
		return rexec(host.hostname, host.port, host.user, host.password, cmd,
163
		return rexec(host.hostname, host.port, host.user, host.password, cmd,
177
				timeout);
164
				timeout);
178
	}
165
	}
179
 
166
 
180
	/*
167
	/*
181
	 * (non-Javadoc)
168
	 * (non-Javadoc)
182
	 * 
169
	 * 
183
	 * @see
170
	 * @see
184
	 * net.brutex.xservices.ws.impl.ExecuteService#runTelnet(net.brutex.xservices
171
	 * net.brutex.xservices.ws.impl.ExecuteService#runTelnet(net.brutex.xservices
185
	 * .types.HostConnection, java.lang.String, java.lang.String,
172
	 * .types.HostConnection, java.lang.String, java.lang.String,
186
	 * java.lang.String, long)
173
	 * java.lang.String, long)
187
	 */
174
	 */
188
	
175
	
189
	@WebMethod(operationName = "telnet")
176
	@WebMethod(operationName = "telnet")
190
	public ReturnCode runTelnet(@WebParam(name = "host") HostConnection host,
177
	public ReturnCode runTelnet(@WebParam(name = "host") HostConnection host,
191
			@WebParam(name = "prompt") String prompt,
178
			@WebParam(name = "prompt") String prompt,
192
			@WebParam(name = "command") String cmd,
179
			@WebParam(name = "command") String cmd,
193
			@WebParam(name = "expect") String expect,
180
			@WebParam(name = "expect") String expect,
194
			@WebParam(name = "timeout") long timeout) {
181
			@WebParam(name = "timeout") long timeout) {
195
		return telnet(host.hostname, host.port, host.user, host.password, cmd,
182
		return telnet(host.hostname, host.port, host.user, host.password, cmd,
196
				timeout, prompt, expect);
183
				timeout, prompt, expect);
197
	}
184
	}
198
 
185
 
199
	
186
	
200
	public void runJScript(String script) throws XServicesFault {
187
	public void runJScript(String script) throws XServicesFault {
201
 
188
 
202
		try {
189
		try {
203
			// Create and enter a Context. A Context stores information about
190
			// Create and enter a Context. A Context stores information about
204
			// the execution environment of a script.
191
			// the execution environment of a script.
205
			Context cx = Context.enter();
192
			Context cx = Context.enter();
206
			cx.setOptimizationLevel(0);
193
			cx.setOptimizationLevel(0);
207
			cx.setLanguageVersion(Context.VERSION_1_7);
194
			cx.setLanguageVersion(Context.VERSION_1_7);
208
			// cx is the Context instance you're using to run scripts
195
			// cx is the Context instance you're using to run scripts
209
			/*
196
			/*
210
			 * cx.setClassShutter(new ClassShutter() { public boolean
197
			 * cx.setClassShutter(new ClassShutter() { public boolean
211
			 * visibleToScripts(String className) {
198
			 * visibleToScripts(String className) {
212
			 * if(className.startsWith("adapter")) return true;
199
			 * if(className.startsWith("adapter")) return true;
213
			 * if(className.startsWith("java.lang.System") ||
200
			 * if(className.startsWith("java.lang.System") ||
214
			 * className.startsWith
201
			 * className.startsWith
215
			 * ("org.apache.tomcat.util.log.SystemLogHandler")) return true;
202
			 * ("org.apache.tomcat.util.log.SystemLogHandler")) return true;
216
			 * System.out.println(className + " is blocked."); return false; }
203
			 * System.out.println(className + " is blocked."); return false; }
217
			 * });
204
			 * });
218
			 */
205
			 */
219
 
206
 
220
			// Initialise the standard objects (Object, Function, etc.). This
207
			// Initialise the standard objects (Object, Function, etc.). This
221
			// must be done before scripts can be
208
			// must be done before scripts can be
222
			// executed. The null parameter tells initStandardObjects
209
			// executed. The null parameter tells initStandardObjects
223
			// to create and return a scope object that we use
210
			// to create and return a scope object that we use
224
			// in later calls.
211
			// in later calls.
225
			Scriptable scope = cx.initStandardObjects();
212
			Scriptable scope = cx.initStandardObjects();
226
			// Object wrappedOut = Context.javaToJS(System.out, scope);
213
			// Object wrappedOut = Context.javaToJS(System.out, scope);
227
			// Object wrappedOut2 = Context.javaToJS(this, scope);
214
			// Object wrappedOut2 = Context.javaToJS(this, scope);
228
			// scope.put("out", scope, wrappedOut);
215
			// scope.put("out", scope, wrappedOut);
229
			// scope.put("exe", scope, wrappedOut2);
216
			// scope.put("exe", scope, wrappedOut2);
230
 
217
 
231
			// Execute the script
218
			// Execute the script
232
			// cx.evaluateString(scope, "importClass('java.lang.System');\n",
219
			// cx.evaluateString(scope, "importClass('java.lang.System');\n",
233
			// "head", 1, null);
220
			// "head", 1, null);
234
			// cx.evaluateString(scope, "importPackage('java.util');\n", "head",
221
			// cx.evaluateString(scope, "importPackage('java.util');\n", "head",
235
			// 2, null);
222
			// 2, null);
236
			Object obj = cx
223
			Object obj = cx
237
					.evaluateString(scope, script, "TestScript", 1, null);
224
					.evaluateString(scope, script, "TestScript", 1, null);
238
 
225
 
239
		} catch (Exception e) {
226
		} catch (Exception e) {
240
			System.out.println(e.getMessage());
227
			System.out.println(e.getMessage());
241
		} finally {
228
		} finally {
242
			// Exit the Context. This removes the association between the
229
			// Exit the Context. This removes the association between the
243
			// Context and the current thread and is an
230
			// Context and the current thread and is an
244
			// essential cleanup action. There should be a call to exit for
231
			// essential cleanup action. There should be a call to exit for
245
			// every call to enter.
232
			// every call to enter.
246
			Context.exit();
233
			Context.exit();
247
		}
234
		}
248
 
235
 
249
	}
236
	}
250
 
237
 
251
	@WebMethod(exclude = true)
238
	@WebMethod(exclude = true)
252
	private ReturnCode executeCommand(String executable, String[] args,
239
	private ReturnCode executeCommand(String executable, String[] args,
253
			File dir, boolean spawn, String inputstring,
240
			File dir, boolean spawn, String inputstring,
254
			boolean newenvironment, boolean vmlauncher, boolean searchpath,
241
			boolean newenvironment, boolean vmlauncher, boolean searchpath,
255
			long timeout) {
242
			long timeout) {
256
		ExecTask exe = new ExecTask();
243
		ExecTask exe = new ExecTask();
257
		RunTask runner = new RunTask(exe);
244
		RunTask runner = new RunTask(exe);
258
 
245
 
259
		/*
246
		/*
260
		 * Commandline cmdl = new Commandline(); cmdl.setExecutable(executable);
247
		 * Commandline cmdl = new Commandline(); cmdl.setExecutable(executable);
261
		 * cmdl.addArguments(args); System.out.println(cmdl.describeCommand());
248
		 * cmdl.addArguments(args); System.out.println(cmdl.describeCommand());
262
		 */
249
		 */
263
 
250
 
264
		exe.setExecutable(executable);
251
		exe.setExecutable(executable);
265
		for (String s : args) {
252
		for (String s : args) {
266
			exe.createArg().setValue(s);
253
			exe.createArg().setValue(s);
267
		}
254
		}
268
 
255
 
269
		exe.setDir(dir);
256
		exe.setDir(dir);
270
		if (spawn) {
257
		if (spawn) {
271
			exe.setSpawn(spawn);
258
			exe.setSpawn(spawn);
272
		} else {
259
		} else {
273
			exe.setTimeout(timeout);
260
			exe.setTimeout(timeout);
274
			exe.setInputString(inputstring);
261
			exe.setInputString(inputstring);
275
			exe.setOutputproperty("ExecuteService.stdout");
262
			exe.setOutputproperty("ExecuteService.stdout");
276
			exe.setErrorProperty("ExecuteService.stderr");
263
			exe.setErrorProperty("ExecuteService.stderr");
277
			exe.setResultProperty("ExecuteService.result");
264
			exe.setResultProperty("ExecuteService.result");
278
		}
265
		}
279
 
266
 
280
		exe.setNewenvironment(newenvironment);
267
		exe.setNewenvironment(newenvironment);
281
		exe.setVMLauncher(vmlauncher);
268
		exe.setVMLauncher(vmlauncher);
282
		exe.setSearchPath(searchpath);
269
		exe.setSearchPath(searchpath);
283
 
270
 
284
		return runner.postTask();
271
		return runner.postTask();
285
	}
272
	}
286
 
273
 
287
	@WebMethod(exclude = true)
274
	@WebMethod(exclude = true)
288
	private ReturnCode sshExec(String host, String username, String password,
275
	private ReturnCode sshExec(String host, String username, String password,
289
			int port, String command, long timeout) {
276
			int port, String command, long timeout) {
290
		SSHExec sshexec = new SSHExec();
277
		SSHExec sshexec = new SSHExec();
291
		RunTask runner = new RunTask(sshexec);
278
		RunTask runner = new RunTask(sshexec);
292
		sshexec.setHost(host);
279
		sshexec.setHost(host);
293
		sshexec.setUsername(username);
280
		sshexec.setUsername(username);
294
		sshexec.setPassword(password);
281
		sshexec.setPassword(password);
295
		sshexec.setPort(port);
282
		sshexec.setPort(port);
296
		sshexec.setCommand(command);
283
		sshexec.setCommand(command);
297
		sshexec.setTrust(true);
284
		sshexec.setTrust(true);
298
		sshexec.setTimeout(timeout);
285
		sshexec.setTimeout(timeout);
299
		sshexec.setOutputproperty("SSHExec.stdout");
286
		sshexec.setOutputproperty("SSHExec.stdout");
300
		return runner.postTask();
287
		return runner.postTask();
301
	}
288
	}
302
 
289
 
303
	@WebMethod(exclude = true)
290
	@WebMethod(exclude = true)
304
	private ReturnCode sshExecWithCert(String host, String username,
291
	private ReturnCode sshExecWithCert(String host, String username,
305
			String passphrase, String keyfile, int port, String command,
292
			String passphrase, String keyfile, int port, String command,
306
			long timeout) {
293
			long timeout) {
307
		SSHExec sshexec = new SSHExec();
294
		SSHExec sshexec = new SSHExec();
308
		RunTask runner = new RunTask(sshexec);
295
		RunTask runner = new RunTask(sshexec);
309
		sshexec.setHost(host);
296
		sshexec.setHost(host);
310
		sshexec.setUsername(username);
297
		sshexec.setUsername(username);
311
		sshexec.setKeyfile(keyfile);
298
		sshexec.setKeyfile(keyfile);
312
		sshexec.setPassphrase(passphrase);
299
		sshexec.setPassphrase(passphrase);
313
		sshexec.setPort(port);
300
		sshexec.setPort(port);
314
		sshexec.setCommand(command);
301
		sshexec.setCommand(command);
315
		sshexec.setTrust(true);
302
		sshexec.setTrust(true);
316
		sshexec.setTimeout(timeout);
303
		sshexec.setTimeout(timeout);
317
		sshexec.setOutputproperty("SSHExec.stdout");
304
		sshexec.setOutputproperty("SSHExec.stdout");
318
		return runner.postTask();
305
		return runner.postTask();
319
	}
306
	}
320
 
307
 
321
	@WebMethod(exclude = true)
308
	@WebMethod(exclude = true)
322
	private ReturnCode rexec(String host, int port, String username,
309
	private ReturnCode rexec(String host, int port, String username,
323
			String password, String command, long timeout) {
310
			String password, String command, long timeout) {
324
		RExecTask rexec = new RExecTask();
311
		RExecTask rexec = new RExecTask();
325
		RunTask runner = new RunTask(rexec);
312
		RunTask runner = new RunTask(rexec);
326
		rexec.setServer(host);
313
		rexec.setServer(host);
327
		rexec.setPort(port);
314
		rexec.setPort(port);
328
		rexec.setUserid(username);
315
		rexec.setUserid(username);
329
		rexec.setPassword(password);
316
		rexec.setPassword(password);
330
		rexec.setCommand(command);
317
		rexec.setCommand(command);
331
		rexec.setTimeout((int) Math.round(timeout));
318
		rexec.setTimeout((int) Math.round(timeout));
332
 
319
 
333
		return runner.postTask();
320
		return runner.postTask();
334
	}
321
	}
335
 
322
 
336
	@WebMethod(exclude = true)
323
	@WebMethod(exclude = true)
337
	private ReturnCode telnet(String host, int port, String username,
324
	private ReturnCode telnet(String host, int port, String username,
338
			String password, String command, long timeout, String prompt,
325
			String password, String command, long timeout, String prompt,
339
			String expect) {
326
			String expect) {
340
		TelnetTask rexec = new TelnetTask();
327
		TelnetTask rexec = new TelnetTask();
341
		RunTask runner = new RunTask(rexec);
328
		RunTask runner = new RunTask(rexec);
342
		rexec.setServer(host);
329
		rexec.setServer(host);
343
		rexec.setPort(port);
330
		rexec.setPort(port);
344
		rexec.setUserid(username);
331
		rexec.setUserid(username);
345
		rexec.setPassword(password);
332
		rexec.setPassword(password);
346
		rexec.setTimeout((int) Math.round(timeout));
333
		rexec.setTimeout((int) Math.round(timeout));
347
 
334
 
348
		rexec.createRead().addText(prompt);
335
		rexec.createRead().addText(prompt);
349
		rexec.createWrite().addText(command);
336
		rexec.createWrite().addText(command);
350
		rexec.createRead().addText(expect);
337
		rexec.createRead().addText(expect);
351
 
338
 
352
		return runner.postTask();
339
		return runner.postTask();
353
	}
340
	}
354
}
341
}