Subversion Repositories XServices

Rev

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

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