source: other-projects/trunk/gs3-release-maker/tasks/sshtaskdef/src/mindbright/application/MindTunnelCli.java@ 14627

Last change on this file since 14627 was 14627, checked in by oranfry, 17 years ago

initial import of the gs3-release-maker

File size: 8.5 KB
Line 
1/******************************************************************************
2 *
3 * Copyright (c) 1998,99 by Mindbright Technology AB, Stockholm, Sweden.
4 * www.mindbright.se, [email protected]
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 *****************************************************************************
17 * $Author: mats $
18 * $Date: 2000/03/24 09:03:42 $
19 * $Name: rel1-2-1 $
20 *****************************************************************************/
21package mindbright.application;
22
23import java.applet.Applet;
24import java.applet.AppletContext;
25
26import java.net.URL;
27import java.net.MalformedURLException;
28
29import java.util.Properties;
30
31import mindbright.ssh.SSH;
32import mindbright.ssh.SSHClient;
33import mindbright.ssh.SSHTunnelingClient;
34import mindbright.ssh.SSHPropertyHandler;
35
36public class MindTunnelCli extends Applet implements Runnable {
37
38 static Properties paramSSHProps = new Properties();
39
40 String[] cmdLineArgs;
41
42 String sshHomeDir = null;
43 String propsFile = null;
44
45 String commandLine = null;
46 String redirURL = null;
47 String redirTarget = null;
48
49 boolean listMode = false;
50 boolean haveTunnelDialog = false;
51 boolean haveSCPDialog = false;
52 boolean haveProxyDialog = false;
53
54 boolean weAreAnApplet = false;
55
56 public MindTunnelCli() {
57 super();
58 }
59
60 public static void main(String[] argv) {
61 MindTunnelCli controller = new MindTunnelCli();
62 controller.cmdLineArgs = argv;
63
64 try {
65 controller.getApplicationParams();
66 } catch (Exception e) {
67 System.out.println("Error: " + e.getMessage());
68 System.exit(1);
69 }
70
71 try {
72 controller.run();
73 } catch (Exception e) {
74 System.out.println("Error, please mail below stack-trace to [email protected]");
75 e.printStackTrace();
76 }
77 }
78
79 public void init() {
80 if(SSH.NETSCAPE_SECURITY_MODEL) {
81 try {
82 netscape.security.PrivilegeManager.enablePrivilege("TerminalEmulator");
83 } catch (netscape.security.ForbiddenTargetException e) {
84 // !!!
85 }
86 }
87
88 getAppletParams();
89 (new Thread(this)).start();
90 }
91
92 public void run() {
93 try {
94 SSHPropertyHandler propsHandler = new SSHPropertyHandler(paramSSHProps);
95
96 if(propsFile != null) {
97 // !!! REMOVE (todo: fix password!)
98 try {
99 propsHandler = SSHPropertyHandler.fromFile(propsFile, "");
100 } catch (SSHClient.AuthFailException e) {
101 throw new Exception("Sorry, can only use passwordless settings files for now");
102 }
103 propsHandler.mergeProperties(paramSSHProps);
104 }
105
106 SSHTunnelingClient client = new SSHTunnelingClient(propsHandler, this);
107
108 client.getPropertyHandler().setSSHHomeDir(sshHomeDir);
109 client.verbose = SSH.DEBUG;
110 client.listMode = listMode;
111 client.haveTunnelDialog = haveTunnelDialog;
112 client.haveSCPDialog = haveSCPDialog;
113 client.haveProxyDialog = haveProxyDialog;
114
115 try {
116 Thread clientThread = new Thread(client);
117 clientThread.start();
118 clientThread.join();
119 if(!weAreAnApplet) {
120 System.exit(0);
121 }
122
123 } catch(InterruptedException e) {
124 // !!!
125 }
126
127 } catch (Exception e) {
128 System.out.println("Error: " + e.getMessage());
129 e.printStackTrace();
130 }
131 }
132
133 public void online() {
134 if(weAreAnApplet) {
135 if(redirURL != null) {
136 try {
137 getAppletContext().showDocument(new URL(redirURL), redirTarget);
138 } catch (MalformedURLException e) {
139 getAppletContext().showStatus("MindTunnel Client, malformed URL: " + redirURL);
140 }
141 }
142 } else {
143 if(commandLine != null) {
144 try {
145 Runtime.getRuntime().exec(commandLine);
146 } catch (Exception e) {
147 System.out.println("Error running external program: " + commandLine);
148 System.out.println("Error is: " + e);
149 }
150 }
151 }
152 }
153
154 public void getApplicationParams() throws Exception {
155 String name;
156 String value;
157 int numOfOpts;
158 int i;
159
160 // First we check the MindTerm options (i.e. not the ssh/terminal-properties)
161 //
162 try {
163 for(i = 0; i < cmdLineArgs.length; i++) {
164 String arg = cmdLineArgs[i];
165 if(!arg.startsWith("--"))
166 break;
167 switch(arg.charAt(2)) {
168 case 'h':
169 sshHomeDir = cmdLineArgs[++i];
170 break;
171 case 'l':
172 listMode = true;
173 break;
174 case 'f':
175 propsFile = cmdLineArgs[++i];
176 break;
177 case 's':
178 haveSCPDialog = true;
179 break;
180 case 't':
181 haveTunnelDialog = true;
182 break;
183 case 'v':
184 System.out.println("verbose mode selected...");
185 SSH.DEBUG = true;
186 break;
187 case 'y':
188 haveProxyDialog = true;
189 break;
190 case 'V':
191 System.out.println(SSH.VER_MINDTERM);
192 System.out.println("SSH protocol version " + SSH.SSH_VER_MAJOR + "." + SSH.SSH_VER_MINOR);
193 System.exit(0);
194 break;
195 case 'D':
196 SSH.DEBUG = true;
197 SSH.DEBUGMORE = true;
198 break;
199 case '?':
200 printHelp();
201 System.exit(0);
202 default:
203 throw new Exception("unknown parameter '" + arg + "'");
204 }
205 }
206 } catch (Exception e) {
207 printHelp();
208 throw e;
209 }
210
211 numOfOpts = i;
212 for(i = numOfOpts; i < cmdLineArgs.length; i += 2) {
213 name = cmdLineArgs[i];
214 if((name.charAt(0) != '-') || ((i + 1) == cmdLineArgs.length))
215 break;
216 name = name.substring(1);
217 value = cmdLineArgs[i + 1];
218 if(SSHPropertyHandler.isProperty(name))
219 paramSSHProps.put(name, value);
220 else
221 System.out.println("Unknown property '" + name + "'");
222 }
223
224 if(i < cmdLineArgs.length) {
225 commandLine = "";
226 for(; i < cmdLineArgs.length; i++) {
227 commandLine += cmdLineArgs[i] + " ";
228 }
229 commandLine = commandLine.trim();
230 }
231
232 }
233
234 public void getAppletParams() {
235 String name;
236 String value;
237 String param;
238 int i;
239
240 weAreAnApplet = true;
241
242 try {
243 SSH.DEBUG = (new Boolean(getParameter("verbose"))).booleanValue();
244 } catch (Exception e) {
245 SSH.DEBUG = false;
246 }
247
248 try {
249 haveTunnelDialog = (new Boolean(getParameter("edittunnels"))).booleanValue();
250 } catch (Exception e) {
251 haveTunnelDialog = false;
252 }
253
254 try {
255 haveSCPDialog = (new Boolean(getParameter("filetransfer"))).booleanValue();
256 } catch (Exception e) {
257 haveSCPDialog = false;
258 }
259
260 try {
261 haveProxyDialog = (new Boolean(getParameter("configproxy"))).booleanValue();
262 } catch (Exception e) {
263 haveProxyDialog = false;
264 }
265
266 try {
267 listMode = (new Boolean(getParameter("listmode"))).booleanValue();
268 } catch (Exception e) {
269 listMode = false;
270 }
271
272 try {
273 SSH.DEBUGMORE = (new Boolean(getParameter("debug"))).booleanValue();
274 SSH.DEBUG = SSH.DEBUGMORE;
275 } catch (Exception e) {
276 }
277
278 sshHomeDir = getParameter("sshhome");
279 propsFile = getParameter("propsfile");
280
281 redirURL = getParameter("redirurl");
282 redirTarget = getParameter("redirtarget");
283
284 for(i = 0; i < SSHPropertyHandler.defaultPropDesc.length; i++) {
285 name = SSHPropertyHandler.defaultPropDesc[i][SSHPropertyHandler.PROP_NAME];
286 value = getParameter(name);
287 if(value != null)
288 paramSSHProps.put(name, value);
289 }
290 i = 0;
291 while((value = getParameter("local" + i)) != null) {
292 paramSSHProps.put("local" + i, value);
293 i++;
294 }
295 i = 0;
296 while((value = getParameter("remote" + i)) != null) {
297 paramSSHProps.put("remote" + i, value);
298 i++;
299 }
300 }
301
302 void printHelp() {
303 System.out.println("usage: MindTunnelCli [options] [properties] [command]");
304 System.out.println("Options:");
305 System.out.println(" --f <file> Use settings from the given file.");
306 System.out.println(" --h dir Name of the MindTerm home-dir (default: ~/mindterm/).");
307 System.out.println(" --l Enables list mode (i.e. lists available settings to choose from).");
308 System.out.println(" --s Enables file transfer dialog. (i.e. scp functionality).");
309 System.out.println(" --t Enables tunnel dialog (i.e. ability to edit tunnels).");
310 System.out.println(" --v Verbose; display verbose messages.");
311 System.out.println(" --y Enables proxy configure dialog (i.e. proxy settings).");
312 System.out.println(" --D Debug; display extra debug info.");
313 System.out.println(" --V Version; display version number only.");
314 System.out.println(" --? Help; display this help.");
315 }
316
317}
Note: See TracBrowser for help on using the repository browser.