15
|
1 package treeVnc;
|
|
2
|
|
3 import java.awt.*;
|
|
4 import java.awt.event.*;
|
|
5 import java.io.*;
|
|
6 import java.net.*;
|
|
7
|
|
8 public class VncProxyService implements java.lang.Runnable {
|
|
9
|
|
10
|
|
11 public void treeVncProxy(String[] argv) {
|
|
12 VncProxyService v = new VncProxyService();
|
|
13
|
|
14 // v.checkArgs(argv);
|
|
15
|
|
16 v.mainArgs = argv;
|
|
17
|
|
18 v.init();
|
|
19 v.start_threads();
|
|
20 }
|
|
21
|
|
22 String[] mainArgs;
|
|
23 String username;
|
|
24
|
|
25 CreateHtmlFile hgtmlFile;
|
|
26
|
|
27 // RfbProto rfb;
|
|
28 MyRfbProtoProxy rfb;
|
|
29 MyRfbProtoProxy testrfb;
|
|
30 Thread rfbThread;
|
|
31 Thread accThread;
|
|
32 Thread clientThread;
|
|
33 private Thread bCast;
|
|
34 CreateThread geth;
|
|
35 AcceptClient acc;
|
|
36 private AcceptThread acceptThread;
|
|
37 private TextBoxProxy getHost;
|
|
38 private GetBroadCastProxy getCast;
|
|
39
|
|
40 Frame vncFrame;
|
|
41 Container vncContainer;
|
|
42 ScrollPane desktopScrollPane;
|
|
43 GridBagLayout gridbag;
|
|
44 ButtonPanel buttonPanel;
|
|
45 Label connStatusLabel;
|
|
46 ProxyVncCanvas vc;
|
|
47 // OptionsFrame options;
|
|
48 OptionsNoFrame options;
|
|
49 ClipboardFrame clipboard;
|
|
50 RecordingFrame rec;
|
|
51
|
|
52 // Control session recording.
|
|
53 Object recordingSync;
|
|
54 String sessionFileName;
|
|
55 boolean recordingActive;
|
|
56 boolean recordingStatusChanged;
|
|
57 String cursorUpdatesDef;
|
|
58 String eightBitColorsDef;
|
|
59
|
|
60 // Variables read from parameter values.
|
|
61 String socketFactory;
|
|
62 String host;
|
|
63 int port = 5900;
|
|
64 String passwordParam;
|
|
65 boolean showControls;
|
|
66 boolean offerRelogin;
|
|
67 boolean showOfflineDesktop;
|
|
68 int deferScreenUpdates;
|
|
69 int deferCursorUpdates;
|
|
70 int deferUpdateRequests;
|
|
71 int debugStatsExcludeUpdates;
|
|
72 int debugStatsMeasureUpdates;
|
|
73
|
|
74 int echoPort = 9999;
|
|
75 private boolean changeFlag;
|
|
76
|
|
77 String url;
|
|
78
|
|
79 // XmlRpc client;
|
|
80 String wpUsername, wpPassword, blogId;
|
|
81 String title = "TreeVNC";
|
|
82
|
|
83 void checkArgs(String[] argv) {
|
|
84 int len = argv.length;
|
|
85
|
|
86 for (int i = 0; i < len; i++) {
|
|
87 String str = argv[i];
|
|
88 if (str.equals("-h") || str.equals("--host")) {
|
|
89 host = argv[++i];
|
|
90 } else if (str.equals("-pn") || str.equals("--port")) {
|
|
91 port = Integer.parseInt(argv[++i]);
|
|
92 } else if (str.equals("-pw") || str.equals("--password")) {
|
|
93 passwordParam = argv[++i];
|
|
94 } else if (str.equals("-w") || str.equals("--wpurl")) {
|
|
95 url = argv[++i];
|
|
96 } else if (str.equals("-wu") || str.equals("--wpusername")) {
|
|
97 wpUsername = argv[++i];
|
|
98 } else if (str.equals("-wp") || str.equals("--wppassword")) {
|
|
99 wpPassword = argv[++i];
|
|
100 } else if (str.equals("-wb") || str.equals("--wpblogId")) {
|
|
101 blogId = argv[++i];
|
|
102 } else if (str.equals("--help")) {
|
|
103 printHelp();
|
|
104 System.exit(0);
|
|
105 } else if (len == 3) {
|
|
106 host = argv[0];
|
|
107 port = Integer.parseInt(argv[1]);
|
|
108 passwordParam = argv[2];
|
|
109 } else if (len == 2) {
|
|
110 host = argv[0];
|
|
111 port = Integer.parseInt(argv[1]);
|
|
112 } else if (len == 1) {
|
|
113 host = argv[0];
|
|
114 }
|
|
115 }
|
|
116 }
|
|
117
|
|
118 void printHelp() {
|
|
119 System.out
|
|
120 .println("usage: java -jar VncProxyService [-h hostname] "
|
|
121 + "[-pn portnumber] [-pw password] [-w WordPressURL] [-wu WPUsername] "
|
|
122 + "[-wp WPPassword] [-wb blogId]");
|
|
123 }
|
|
124
|
|
125 //
|
|
126 // init()
|
|
127 //
|
|
128
|
|
129 public void init() {
|
|
130
|
|
131 readParameters();
|
|
132
|
|
133 options = new OptionsNoFrame(this);
|
|
134 recordingSync = new Object();
|
|
135
|
|
136 sessionFileName = null;
|
|
137 recordingActive = false;
|
|
138 recordingStatusChanged = false;
|
|
139 cursorUpdatesDef = null;
|
|
140 eightBitColorsDef = null;
|
|
141
|
|
142 try {
|
|
143 connectAndAuthenticate();
|
|
144 doProtocolInitialisation();
|
|
145 } catch (NoRouteToHostException e) {
|
|
146 fatalError("Network error: no route to server: " + host, e);
|
|
147 } catch (UnknownHostException e) {
|
|
148 fatalError("Network error: server name unknown: " + host, e);
|
|
149 } catch (ConnectException e) {
|
|
150 fatalError("Network error: could not connect to server: " + host
|
|
151 + ":" + port, e);
|
|
152 } catch (IOException e) {
|
|
153 fatalError("Network error: faild connect or authenticate to server");
|
|
154 } catch (Exception e) {
|
|
155
|
|
156 }
|
|
157 /*
|
|
158 if(changeFlag){
|
|
159 acceptThread.changeRfb(rfb);
|
|
160 } else {*/
|
|
161 rfb.selectPort(5999);
|
|
162 rfbThread = new Thread(this);
|
|
163 acceptThread = new AcceptThread(rfb, 5999);
|
|
164 accThread = new Thread(acceptThread);
|
|
165 getCast = new GetBroadCastProxy(this);
|
|
166 bCast = new Thread(getCast);
|
|
167 //broadCast.udpTransmission(rfb.acceptPort+"-"+host+"-"+rfb.desktopName);
|
|
168 //}
|
|
169 /*
|
|
170 * if(url != null) { try { client = new XmlRpc(blogId, wpUsername,
|
|
171 * wpPassword, url ); InetAddress addr = InetAddress.getLocalHost();
|
|
172 * String add = new String(addr.getHostAddress());
|
|
173 * client.addDescription(rfb.desktopName); setStatusXmlRpc(client,
|
|
174 * title, add, rfb.acceptPort); client.editPost();
|
|
175 * System.out.println("URL:\n" + client.getUrl() + "\n"); } catch
|
|
176 * (MalformedURLException e) {
|
|
177 * System.out.println("Faild create instance of class XmlRpc");
|
|
178 * e.printStackTrace(); } catch (UnknownHostException e) {
|
|
179 * e.printStackTrace(); } }
|
|
180 */
|
|
181
|
|
182 }
|
|
183
|
|
184
|
|
185 public void changeInit() throws Exception {
|
|
186 VncProxyService v = new VncProxyService();
|
|
187 v.changeFlag = true;
|
|
188 //v.checkArgs(argv);
|
|
189
|
|
190 v.mainArgs = new String[0];
|
|
191 v.host = host;
|
|
192 v.init();
|
|
193 v.start_threads();
|
|
194
|
|
195 Thread.sleep(10000);
|
|
196 //rfb = v.rfb;
|
|
197 rfb.is = v.rfb.is;
|
|
198 rfb.os = v.rfb.os;
|
|
199 rfb.initData = v.rfb.initData;
|
|
200
|
|
201 //changeConnection();
|
|
202 // doProtocolInitialisation();
|
|
203
|
|
204 //readParameters();
|
|
205 options = new OptionsNoFrame(this);
|
|
206 recordingSync = new Object();
|
|
207
|
|
208 sessionFileName = null;
|
|
209 recordingActive = false;
|
|
210 recordingStatusChanged = false;
|
|
211 cursorUpdatesDef = null;
|
|
212 eightBitColorsDef = null;
|
|
213
|
|
214 try {
|
|
215 changeConnection();
|
|
216 doProtocolInitialisation();
|
|
217 } catch (NoRouteToHostException e) {
|
|
218 fatalError("Network error: no route to server: " + host, e);
|
|
219 } catch (UnknownHostException e) {
|
|
220 fatalError("Network error: server name unknown: " + host, e);
|
|
221 } catch (ConnectException e) {
|
|
222 fatalError("Network error: could not connect to server: " + host
|
|
223 + ":" + port, e);
|
|
224 } catch (IOException e) {
|
|
225 fatalError("Network error: faild connect or authenticate to server");
|
|
226 } catch (Exception e) {
|
|
227
|
|
228 }
|
|
229
|
|
230 //acceptThread.changeRfb(rfb);
|
|
231 //vc.rfb = rfb;
|
|
232 //rfbThread.start();
|
|
233
|
|
234 }
|
|
235
|
|
236 /*
|
|
237 * void setStatusXmlRpc(XmlRpc client, String title, String hostname, int
|
|
238 * port) { client.setTitle(title); String description =
|
|
239 * makeDescription(hostname, Integer.toString(port));
|
|
240 * client.addDescription(description); }
|
|
241 */
|
|
242 String makeDescription(String hostname, String port) {
|
|
243 String description = "<h1>" + hostname + " " + port + "<h1>\n";
|
|
244 return description;
|
|
245 }
|
|
246
|
|
247 public void start_threads() {
|
|
248 rfbThread.start();
|
|
249 accThread.start();
|
|
250 bCast.start();
|
|
251 rfb.requestThreadStart();
|
|
252 }
|
|
253
|
|
254 //
|
|
255 // run() - executed by the rfbThread to deal with the RFB socket.
|
|
256 //
|
|
257 public void run() {
|
|
258
|
|
259 try {
|
|
260 // connectAndAuthenticate();
|
|
261 // doProtocolInitialisation();
|
|
262 /*
|
|
263 * htmlFile = new CreateHtmlFile(rfb, host, username);
|
|
264 * htmlFile.createHtml();
|
|
265 */
|
|
266 vc = new ProxyVncCanvas(this, 0, 0);
|
|
267 vc.updateFramebufferSize();
|
|
268
|
|
269 processNormalProtocol();// main loop
|
|
270
|
|
271 } catch (NoRouteToHostException e) {
|
|
272 fatalError("Network error: no route to server: " + host, e);
|
|
273 } catch (UnknownHostException e) {
|
|
274 fatalError("Network error: server name unknown: " + host, e);
|
|
275 } catch (ConnectException e) {
|
|
276 fatalError("Network error: could not connect to server: " + host
|
|
277 + ":" + port, e);
|
|
278 } catch (EOFException e) {
|
|
279 if (showOfflineDesktop) {
|
|
280 e.printStackTrace();
|
|
281 System.out
|
|
282 .println("Network error: remote side closed connection");
|
|
283 if (vc != null) {
|
|
284 vc.enableInput(false);
|
|
285 }
|
|
286 if (rfb != null && !rfb.closed())
|
|
287 rfb.close();
|
|
288 if (showControls && buttonPanel != null) {
|
|
289 buttonPanel.disableButtonsOnDisconnect();
|
|
290 }
|
|
291 } else {
|
|
292 fatalError("Network error: remote side closed connection", e);
|
|
293 }
|
|
294 } catch (IOException e) {
|
|
295 String str = e.getMessage();
|
|
296 if (str != null && str.length() != 0) {
|
|
297 fatalError("Network Error: " + str, e);
|
|
298 } else {
|
|
299 fatalError(e.toString(), e);
|
|
300 }
|
|
301 } catch (Exception e) {
|
|
302 String str = e.getMessage();
|
|
303 if (str != null && str.length() != 0) {
|
|
304 fatalError("Error: " + str, e);
|
|
305 } else {
|
|
306 fatalError(e.toString(), e);
|
|
307 }
|
|
308 }
|
|
309
|
|
310 }
|
|
311
|
|
312 //
|
|
313 // Process RFB socket messages.
|
|
314 // If the rfbThread is being stopped, ignore any exceptions,
|
|
315 // otherwise rethrow the exception so it can be handled.
|
|
316 //
|
|
317
|
|
318 void processNormalProtocol() throws Exception {
|
|
319 try {
|
|
320 vc.processNormalProtocol();// main loop
|
|
321 } catch (Exception e) {
|
|
322 if (rfbThread == null) {
|
|
323 System.out.println("Ignoring RFB socket exceptions"
|
|
324 + " because applet is stopping");
|
|
325 } else {
|
|
326 throw e;
|
|
327 }
|
|
328 }
|
|
329 }
|
|
330
|
|
331 //
|
|
332 // Connect to the RFB server and authenticate the user.
|
|
333 //
|
|
334
|
|
335 void connectAndAuthenticate() throws Exception {
|
|
336 if (mainArgs.length == 0)
|
|
337 acc = new AcceptClient(host);
|
|
338 //acc = new AcceptClient(getHost.getAddress());
|
|
339 // acc = new AcceptClient();
|
|
340 else
|
|
341 acc = new AcceptClient(mainArgs[0]);
|
|
342 geth = new CreateThread(acc, echoPort);
|
|
343 Thread thread = new Thread(geth);
|
|
344 thread.start();
|
|
345
|
|
346 showConnectionStatus("Initializing...");
|
|
347
|
|
348 showConnectionStatus("Connecting to " + host + ", port " + port + "...");
|
|
349
|
|
350 rfb = new MyRfbProtoProxy(host, port, geth);
|
|
351
|
|
352 showConnectionStatus("Connected to server");
|
|
353
|
|
354 rfb.readVersionMsg();
|
|
355 showConnectionStatus("RFB server supports protocol version "
|
|
356 + rfb.serverMajor + "." + rfb.serverMinor);
|
|
357
|
|
358 rfb.writeVersionMsg();
|
|
359 showConnectionStatus("Using RFB protocol version " + rfb.clientMajor
|
|
360 + "." + rfb.clientMinor);
|
|
361
|
|
362 int secType = rfb.negotiateSecurity();
|
|
363 int authType;
|
|
364 if (secType == RfbProto.SecTypeTight) {
|
|
365 showConnectionStatus("Enabling TightVNC protocol extensions");
|
|
366 rfb.setupTunneling();
|
|
367 authType = rfb.negotiateAuthenticationTight();
|
|
368 } else {
|
|
369 authType = secType;
|
|
370 }
|
|
371
|
|
372 switch (authType) {
|
|
373 case MyRfbProtoProxy.AuthAccess:
|
|
374 rfb.authenticationRequestAccess();
|
|
375 System.out.println("authenticateion Request right of Acces");
|
|
376 break;
|
|
377 case RfbProto.AuthNone:
|
|
378 showConnectionStatus("No authentication needed");
|
|
379 rfb.authenticateNone();
|
|
380 break;
|
|
381 case RfbProto.AuthVNC:
|
|
382 showConnectionStatus("Performing standard VNC authentication");
|
|
383 if (passwordParam != null) {
|
|
384 rfb.authenticateVNC(passwordParam);
|
|
385 } else {
|
|
386 String pw = askPassword();
|
|
387 rfb.authenticateVNC(pw);
|
|
388 }
|
|
389 break;
|
|
390 default:
|
|
391 throw new Exception("Unknown authentication scheme " + authType);
|
|
392 }
|
|
393 }
|
|
394
|
|
395 void changeConnection() throws Exception {
|
|
396 /*
|
|
397 acc = new AcceptClient(getHost.getAddress());
|
|
398 geth = new CreateThread(acc, echoPort);
|
|
399 Thread thread = new Thread(geth);
|
|
400 thread.start();
|
|
401 */
|
|
402 showConnectionStatus("Initializing...");
|
|
403
|
|
404 showConnectionStatus("Connecting to " + host + ", port " + port + "...");
|
|
405
|
|
406 //rfb = null;
|
|
407 //rfb.is = null;
|
|
408
|
|
409 testrfb = new MyRfbProtoProxy(host, port);
|
|
410 showConnectionStatus("Connected to server");
|
|
411
|
|
412 testrfb.readVersionMsg();
|
|
413 showConnectionStatus("RFB server supports protocol version "
|
|
414 + testrfb.serverMajor + "." + testrfb.serverMinor);
|
|
415
|
|
416 testrfb.writeVersionMsg();
|
|
417 showConnectionStatus("Using RFB protocol version " + testrfb.clientMajor
|
|
418 + "." + testrfb.clientMinor);
|
|
419
|
|
420 int secType = testrfb.negotiateSecurity();
|
|
421 int authType;
|
|
422 if (secType == RfbProto.SecTypeTight) {
|
|
423 showConnectionStatus("Enabling TightVNC protocol extensions");
|
|
424 testrfb.setupTunneling();
|
|
425 authType = testrfb.negotiateAuthenticationTight();
|
|
426 } else {
|
|
427 authType = secType;
|
|
428 }
|
|
429
|
|
430 switch (authType) {
|
|
431 case MyRfbProtoProxy.AuthAccess:
|
|
432 testrfb.authenticationRequestAccess();
|
|
433 System.out.println("authenticateion Request right of Acces");
|
|
434 break;
|
|
435 case RfbProto.AuthNone:
|
|
436 showConnectionStatus("No authentication needed");
|
|
437 testrfb.authenticateNone();
|
|
438 break;
|
|
439 case RfbProto.AuthVNC:
|
|
440 showConnectionStatus("Performing standard VNC authentication");
|
|
441 if (passwordParam != null) {
|
|
442 testrfb.authenticateVNC(passwordParam);
|
|
443 } else {
|
|
444 String pw = askPassword();
|
|
445 testrfb.authenticateVNC(pw);
|
|
446 }
|
|
447 break;
|
|
448 default:
|
|
449 throw new Exception("Unknown authentication scheme " + authType);
|
|
450 }
|
|
451 //rfb.is = testrfb.is;
|
|
452 //rfb.os = testrfb.os;
|
|
453 //rfb = testrfb;
|
|
454 }
|
|
455
|
|
456 //
|
|
457 // Show a message describing the connection status.
|
|
458 // To hide the connection status label, use (msg == null).
|
|
459 //
|
|
460
|
|
461 void showConnectionStatus(String msg) {
|
|
462 System.out.println(msg);
|
|
463 }
|
|
464
|
|
465 //
|
|
466 // Show an authentication panel.
|
|
467 //
|
|
468
|
|
469 String askPassword() throws Exception {
|
|
470 /*
|
|
471 * showConnectionStatus(null); AuthPanel authPanel = new
|
|
472 * AuthPanel(this);
|
|
473 *
|
|
474 * GridBagConstraints gbc = new GridBagConstraints(); gbc.gridwidth =
|
|
475 * GridBagConstraints.REMAINDER; gbc.anchor =
|
|
476 * GridBagConstraints.NORTHWEST; gbc.weightx = 1.0; gbc.weighty = 1.0;
|
|
477 * gbc.ipadx = 100; gbc.ipady = 50; gridbag.setConstraints(authPanel,
|
|
478 * gbc); vncContainer.add(authPanel);
|
|
479 *
|
|
480 *
|
|
481 * authPanel.moveFocusToDefaultField(); vncContainer.remove(authPanel);
|
|
482 */
|
|
483 showConnectionStatus("ask password...");
|
|
484 String pw;
|
|
485 if (mainArgs.length != 0)
|
|
486 pw = mainArgs[2];
|
|
487 else
|
|
488 pw = getHost.getPassword();
|
|
489 return pw;
|
|
490 }
|
|
491
|
|
492 //
|
|
493 // Do the rest of the protocol initialisation.
|
|
494 //
|
|
495
|
|
496 void doProtocolInitialisation() throws IOException {
|
|
497 rfb.writeClientInit();
|
|
498 rfb.readServerInit();
|
|
499
|
|
500 System.out.println("Desktop name is " + rfb.desktopName);
|
|
501 System.out.println("Desktop size is " + rfb.framebufferWidth + " x "
|
|
502 + rfb.framebufferHeight);
|
|
503
|
|
504 setEncodings();
|
|
505
|
|
506 // showConnectionStatus(null);
|
|
507 }
|
|
508
|
|
509 //
|
|
510 // Send current encoding list to the RFB server.
|
|
511 //
|
|
512
|
|
513 int[] encodingsSaved;
|
|
514 int nEncodingsSaved;
|
|
515
|
|
516 void setEncodings() {
|
|
517 setEncodings(false);
|
|
518 }
|
|
519
|
|
520 void autoSelectEncodings() {
|
|
521 setEncodings(true);
|
|
522 }
|
|
523
|
|
524 void setEncodings(boolean autoSelectOnly) {
|
|
525 if (options == null || rfb == null || !rfb.inNormalProtocol)
|
|
526 return;
|
|
527
|
|
528 int preferredEncoding = options.preferredEncoding;
|
|
529 if (preferredEncoding == -1) {
|
|
530 long kbitsPerSecond = rfb.kbitsPerSecond();
|
|
531 /*
|
|
532 * if (nEncodingsSaved < 1) { // Choose Tight or ZRLE encoding for
|
|
533 * the very first update.
|
|
534 * System.out.println("Using Tight/ZRLE encodings");
|
|
535 * preferredEncoding = RfbProto.EncodingTight; } else if
|
|
536 * (kbitsPerSecond > 2000 && encodingsSaved[0] !=
|
|
537 * RfbProto.EncodingHextile) { // Switch to Hextile if the
|
|
538 * connection speed is above 2Mbps. System.out.println("Throughput "
|
|
539 * + kbitsPerSecond + " kbit/s - changing to Hextile encoding");
|
|
540 * preferredEncoding = RfbProto.EncodingHextile; } else if
|
|
541 * (kbitsPerSecond < 1000 && encodingsSaved[0] !=
|
|
542 * RfbProto.EncodingTight) { // Switch to Tight/ZRLE if the
|
|
543 * connection speed is below 1Mbps. System.out.println("Throughput "
|
|
544 * + kbitsPerSecond + " kbit/s - changing to Tight/ZRLE encodings");
|
|
545 * preferredEncoding = RfbProto.EncodingTight; } else { // Don't
|
|
546 * change the encoder. if (autoSelectOnly) return; preferredEncoding
|
|
547 * = encodingsSaved[0]; }
|
|
548 */
|
|
549 } else {
|
|
550 // Auto encoder selection is not enabled.
|
|
551 if (autoSelectOnly)
|
|
552 return;
|
|
553 }
|
|
554
|
|
555 int[] encodings = new int[20];
|
|
556 int nEncodings = 0;
|
|
557
|
|
558 encodings[nEncodings++] = preferredEncoding;
|
|
559
|
|
560 if (options.useCopyRect) {
|
|
561 encodings[nEncodings++] = RfbProto.EncodingCopyRect;
|
|
562 }
|
|
563 /*
|
|
564 * if (preferredEncoding != RfbProto.EncodingTight) {
|
|
565 * encodings[nEncodings++] = RfbProto.EncodingTight; }
|
|
566 */
|
|
567
|
|
568 if (preferredEncoding != RfbProto.EncodingZRLE) {
|
|
569 encodings[nEncodings++] = RfbProto.EncodingZRLE;
|
|
570 }
|
|
571 /*
|
|
572 * if (preferredEncoding != RfbProto.EncodingHextile) {
|
|
573 * encodings[nEncodings++] = RfbProto.EncodingHextile; } if
|
|
574 * (preferredEncoding != RfbProto.EncodingZlib) {
|
|
575 * encodings[nEncodings++] = RfbProto.EncodingZlib; }
|
|
576 */
|
|
577 /*
|
|
578 * if (preferredEncoding != RfbProto.EncodingCoRRE) {
|
|
579 * encodings[nEncodings++] = RfbProto.EncodingCoRRE; } if
|
|
580 * (preferredEncoding != RfbProto.EncodingRRE) { encodings[nEncodings++]
|
|
581 * = RfbProto.EncodingRRE; }
|
|
582 */
|
|
583 /*
|
|
584 * if (options.compressLevel >= 0 && options.compressLevel <= 9) {
|
|
585 * encodings[nEncodings++] = RfbProto.EncodingCompressLevel0 +
|
|
586 * options.compressLevel; } if (options.jpegQuality >= 0 &&
|
|
587 * options.jpegQuality <= 9) { encodings[nEncodings++] =
|
|
588 * RfbProto.EncodingQualityLevel0 + options.jpegQuality; } if
|
|
589 * (options.requestCursorUpdates) { encodings[nEncodings++] =
|
|
590 * RfbProto.EncodingXCursor; encodings[nEncodings++] =
|
|
591 * RfbProto.EncodingRichCursor; if (!options.ignoreCursorUpdates)
|
|
592 * encodings[nEncodings++] = RfbProto.EncodingPointerPos; }
|
|
593 */
|
|
594
|
|
595 encodings[nEncodings++] = RfbProto.EncodingLastRect;
|
|
596 encodings[nEncodings++] = RfbProto.EncodingNewFBSize;
|
|
597
|
|
598 boolean encodingsWereChanged = false;
|
|
599 if (nEncodings != nEncodingsSaved) {
|
|
600 encodingsWereChanged = true;
|
|
601 } else {
|
|
602 for (int i = 0; i < nEncodings; i++) {
|
|
603 if (encodings[i] != encodingsSaved[i]) {
|
|
604 encodingsWereChanged = true;
|
|
605 break;
|
|
606 }
|
|
607 }
|
|
608 }
|
|
609
|
|
610 if (encodingsWereChanged) {
|
|
611 try {
|
|
612 rfb.writeSetEncodings(encodings, nEncodings);
|
|
613 if (vc != null) {
|
|
614 vc.softCursorFree();
|
|
615 }
|
|
616 } catch (Exception e) {
|
|
617 e.printStackTrace();
|
|
618 }
|
|
619 encodingsSaved = encodings;
|
|
620 nEncodingsSaved = nEncodings;
|
|
621 }
|
|
622 }
|
|
623
|
|
624 //
|
|
625 // setCutText() - send the given cut text to the RFB server.
|
|
626 //
|
|
627
|
|
628 void setCutText(String text) {
|
|
629 try {
|
|
630 if (rfb != null && rfb.inNormalProtocol) {
|
|
631 rfb.writeClientCutText(text);
|
|
632 }
|
|
633 } catch (Exception e) {
|
|
634 e.printStackTrace();
|
|
635 }
|
|
636 }
|
|
637
|
|
638 //
|
|
639 // Order change in session recording status. To stop recording, pass
|
|
640 // null in place of the fname argument.
|
|
641 //
|
|
642
|
|
643 void setRecordingStatus(String fname) {
|
|
644 synchronized (recordingSync) {
|
|
645 sessionFileName = fname;
|
|
646 recordingStatusChanged = true;
|
|
647 }
|
|
648 }
|
|
649
|
|
650 //
|
|
651 // Start or stop session recording. Returns true if this method call
|
|
652 // causes recording of a new session.
|
|
653 //
|
|
654
|
|
655 boolean checkRecordingStatus() throws IOException {
|
|
656 synchronized (recordingSync) {
|
|
657 if (recordingStatusChanged) {
|
|
658 recordingStatusChanged = false;
|
|
659 if (sessionFileName != null) {
|
|
660 startRecording();
|
|
661 return true;
|
|
662 } else {
|
|
663 stopRecording();
|
|
664 }
|
|
665 }
|
|
666 }
|
|
667 return false;
|
|
668 }
|
|
669
|
|
670 //
|
|
671 // Start session recording.
|
|
672 //
|
|
673
|
|
674 protected void startRecording() throws IOException {
|
|
675 synchronized (recordingSync) {
|
|
676 if (!recordingActive) {
|
|
677 // Save settings to restore them after recording the session.
|
|
678 cursorUpdatesDef = options.choices[options.cursorUpdatesIndex]
|
|
679 .getSelectedItem();
|
|
680 eightBitColorsDef = options.choices[options.eightBitColorsIndex]
|
|
681 .getSelectedItem();
|
|
682 // Set options to values suitable for recording.
|
|
683 options.choices[options.cursorUpdatesIndex].select("Disable");
|
|
684 options.choices[options.cursorUpdatesIndex].setEnabled(false);
|
|
685 options.setEncodings();
|
|
686 options.choices[options.eightBitColorsIndex].select("No");
|
|
687 options.choices[options.eightBitColorsIndex].setEnabled(false);
|
|
688 options.setColorFormat();
|
|
689 } else {
|
|
690 rfb.closeSession();
|
|
691 }
|
|
692
|
|
693 System.out.println("Recording the session in " + sessionFileName);
|
|
694 rfb.startSession(sessionFileName);
|
|
695 recordingActive = true;
|
|
696 }
|
|
697 }
|
|
698
|
|
699 //
|
|
700 // Stop session recording.
|
|
701 //
|
|
702
|
|
703 protected void stopRecording() throws IOException {
|
|
704 synchronized (recordingSync) {
|
|
705 if (recordingActive) {
|
|
706 // Restore options.
|
|
707 options.choices[options.cursorUpdatesIndex]
|
|
708 .select(cursorUpdatesDef);
|
|
709 options.choices[options.cursorUpdatesIndex].setEnabled(true);
|
|
710 options.setEncodings();
|
|
711 options.choices[options.eightBitColorsIndex]
|
|
712 .select(eightBitColorsDef);
|
|
713 options.choices[options.eightBitColorsIndex].setEnabled(true);
|
|
714 options.setColorFormat();
|
|
715
|
|
716 rfb.closeSession();
|
|
717 System.out.println("Session recording stopped.");
|
|
718 }
|
|
719 sessionFileName = null;
|
|
720 recordingActive = false;
|
|
721 }
|
|
722 }
|
|
723
|
|
724 //
|
|
725 // readParameters() - read parameters from the html source or from the
|
|
726 // command line. On the command line, the arguments are just a sequence of
|
|
727 // param_name/param_value pairs where the names and values correspond to
|
|
728 // those expected in the html applet tag source.
|
|
729 //
|
|
730
|
|
731 void readParameters() {
|
|
732 if (!(changeFlag)) {
|
|
733 if (mainArgs.length == 0) {
|
|
734 getHost = new TextBoxProxy(this);
|
|
735 getHost.ipRegister();
|
|
736 host = getHost.getAddress();
|
|
737 } else {
|
|
738 host = mainArgs[0];
|
|
739 }
|
|
740
|
|
741 if (mainArgs.length < 2) {
|
|
742 port = Integer.parseInt(getHost.getPort());
|
|
743 // port = 5900;
|
|
744 } else {
|
|
745 port = Integer.parseInt(mainArgs[1]);
|
|
746 }
|
|
747 } else {
|
|
748 getHost = new TextBoxProxy(this);
|
|
749 port = 5900;
|
|
750 }
|
|
751 if(getHost==null){
|
|
752 getHost = new TextBoxProxy(this);
|
|
753 //getHost.changeHost();
|
|
754 } else {
|
|
755 //getHost.changeHost();
|
|
756 }
|
|
757
|
|
758 // Read "ENCPASSWORD" or "PASSWORD" parameter if specified.
|
|
759 // readPasswordParameters();
|
|
760
|
|
761 String str;
|
|
762
|
|
763 // "Show Controls" set to "No" disables button panel.
|
|
764 showControls = true;
|
|
765 str = readParameter("Show Controls", false);
|
|
766 if (str != null && str.equalsIgnoreCase("No"))
|
|
767 showControls = false;
|
|
768
|
|
769 // "Offer Relogin" set to "No" disables "Login again" and "Close
|
|
770 // window" buttons under error messages in applet mode.
|
|
771 offerRelogin = true;
|
|
772 str = readParameter("Offer Relogin", false);
|
|
773 if (str != null && str.equalsIgnoreCase("No"))
|
|
774 offerRelogin = false;
|
|
775
|
|
776 // Do we continue showing desktop on remote disconnect?
|
|
777 showOfflineDesktop = false;
|
|
778 str = readParameter("Show Offline Desktop", false);
|
|
779 if (str != null && str.equalsIgnoreCase("Yes"))
|
|
780 showOfflineDesktop = true;
|
|
781
|
|
782 // Fine tuning options.
|
|
783 deferScreenUpdates = readIntParameter("Defer screen updates", 20);
|
|
784 deferCursorUpdates = readIntParameter("Defer cursor updates", 10);
|
|
785 deferUpdateRequests = readIntParameter("Defer update requests", 0);
|
|
786
|
|
787 // Debugging options.
|
|
788 debugStatsExcludeUpdates = readIntParameter("DEBUG_XU", 0);
|
|
789 debugStatsMeasureUpdates = readIntParameter("DEBUG_CU", 0);
|
|
790
|
|
791 // SocketFactory.
|
|
792 socketFactory = readParameter("SocketFactory", false);
|
|
793 }
|
|
794
|
|
795 //
|
|
796 // Read password parameters. If an "ENCPASSWORD" parameter is set,
|
|
797 // then decrypt the password into the passwordParam string. Otherwise,
|
|
798 // try to read the "PASSWORD" parameter directly to passwordParam.
|
|
799 //
|
|
800
|
|
801 private void readPasswordParameters() {
|
|
802 String encPasswordParam;
|
|
803 // String encPasswordParam = readParameter("ENCPASSWORD", false);
|
|
804 if (mainArgs.length != 0)
|
|
805 encPasswordParam = mainArgs[2];
|
|
806 else
|
|
807 encPasswordParam = getHost.getPassword();
|
|
808
|
|
809 if (encPasswordParam == null) {
|
|
810 // passwordParam = readParameter("PASSWORD", false);
|
|
811
|
|
812 } else {
|
|
813 // ENCPASSWORD is hexascii-encoded. Decode.
|
|
814 byte[] pw = { 0, 0, 0, 0, 0, 0, 0, 0 };
|
|
815 int len = encPasswordParam.length() / 2;
|
|
816 if (len > 8)
|
|
817 len = 8;
|
|
818 for (int i = 0; i < len; i++) {
|
|
819 String hex = encPasswordParam.substring(i * 2, i * 2 + 2);
|
|
820 Integer x = new Integer(Integer.parseInt(hex, 16));
|
|
821 pw[i] = x.byteValue();
|
|
822 }
|
|
823 // Decrypt the password.
|
|
824 byte[] key = { 23, 82, 107, 6, 35, 78, 88, 7 };
|
|
825 DesCipher des = new DesCipher(key);
|
|
826 des.decrypt(pw, 0, pw, 0);
|
|
827 passwordParam = new String(pw);
|
|
828
|
|
829 }
|
|
830 }
|
|
831
|
|
832 public String readParameter(String name, boolean required) {
|
|
833 if(mainArgs!=null){
|
|
834 for (int i = 0; i < mainArgs.length; i += 2) {
|
|
835 if (mainArgs[i].equalsIgnoreCase(name)) {
|
|
836 try {
|
|
837 return mainArgs[i + 1];
|
|
838 } catch (Exception e) {
|
|
839 if (required) {
|
|
840 fatalError(name + " parameter not specified");
|
|
841 }
|
|
842 return null;
|
|
843 }
|
|
844 }
|
|
845 }
|
|
846 if (required) {
|
|
847 fatalError(name + " parameter not specified");
|
|
848 }
|
|
849 }
|
|
850 return null;
|
|
851 }
|
|
852
|
|
853 int readIntParameter(String name, int defaultValue) {
|
|
854 String str = readParameter(name, false);
|
|
855 int result = defaultValue;
|
|
856 if (str != null) {
|
|
857 try {
|
|
858 result = Integer.parseInt(str);
|
|
859 } catch (NumberFormatException e) {
|
|
860 }
|
|
861 }
|
|
862 return result;
|
|
863 }
|
|
864
|
|
865 //
|
|
866 // disconnect() - close connection to server.
|
|
867 //
|
|
868
|
|
869 synchronized public void disconnect() {
|
|
870 System.out.println("Disconnecting");
|
|
871
|
|
872 if (vc != null) {
|
|
873 double sec = (System.currentTimeMillis() - vc.statStartTime) / 1000.0;
|
|
874 double rate = Math.round(vc.statNumUpdates / sec * 100) / 100.0;
|
|
875 int nRealRects = vc.statNumPixelRects;
|
|
876 int nPseudoRects = vc.statNumTotalRects - vc.statNumPixelRects;
|
|
877 System.out.println("Updates received: " + vc.statNumUpdates + " ("
|
|
878 + nRealRects + " rectangles + " + nPseudoRects
|
|
879 + " pseudo), " + rate + " updates/sec");
|
|
880 int numRectsOther = nRealRects - vc.statNumRectsTight
|
|
881 - vc.statNumRectsZRLE - vc.statNumRectsHextile
|
|
882 - vc.statNumRectsRaw - vc.statNumRectsCopy;
|
|
883 System.out.println("Rectangles:" + " Tight=" + vc.statNumRectsTight
|
|
884 + "(JPEG=" + vc.statNumRectsTightJPEG + ") ZRLE="
|
|
885 + vc.statNumRectsZRLE + " Hextile="
|
|
886 + vc.statNumRectsHextile + " Raw=" + vc.statNumRectsRaw
|
|
887 + " CopyRect=" + vc.statNumRectsCopy + " other="
|
|
888 + numRectsOther);
|
|
889
|
|
890 int raw = vc.statNumBytesDecoded;
|
|
891 int compressed = vc.statNumBytesEncoded;
|
|
892 if (compressed > 0) {
|
|
893 double ratio = Math.round((double) raw / compressed * 1000) / 1000.0;
|
|
894 System.out.println("Pixel data: " + vc.statNumBytesDecoded
|
|
895 + " bytes, " + vc.statNumBytesEncoded
|
|
896 + " compressed, ratio " + ratio);
|
|
897 }
|
|
898 }
|
|
899
|
|
900 if (rfb != null && !rfb.closed())
|
|
901 rfb.close();
|
|
902 // options.dispose();
|
|
903 clipboard.dispose();
|
|
904 if (rec != null)
|
|
905 rec.dispose();
|
|
906
|
|
907 System.exit(0);
|
|
908
|
|
909 }
|
|
910
|
|
911 //
|
|
912 // fatalError() - print out a fatal error message.
|
|
913 // FIXME: Do we really need two versions of the fatalError() method?
|
|
914 //
|
|
915
|
|
916 synchronized public void fatalError(String str) {
|
|
917 System.out.println(str);
|
|
918 System.exit(1);
|
|
919 }
|
|
920
|
|
921 synchronized public void fatalError(String str, Exception e) {
|
|
922
|
|
923 if (rfb != null && rfb.closed()) {
|
|
924 // Not necessary to show error message if the error was caused
|
|
925 // by I/O problems after the rfb.close() method call.
|
|
926 System.out.println("RFB thread finished");
|
|
927 return;
|
|
928 }
|
|
929
|
|
930 System.out.println(str);
|
|
931 e.printStackTrace();
|
|
932
|
|
933 if (rfb != null)
|
|
934 rfb.close();
|
|
935
|
|
936 System.exit(1);
|
|
937
|
|
938 }
|
|
939
|
|
940 //
|
|
941 // Show message text and optionally "Relogin" and "Close" buttons.
|
|
942 //
|
|
943
|
|
944 void showMessage(String msg) {
|
|
945 vncContainer.removeAll();
|
|
946
|
|
947 Label errLabel = new Label(msg, Label.CENTER);
|
|
948 errLabel.setFont(new Font("Helvetica", Font.PLAIN, 12));
|
|
949
|
|
950 if (offerRelogin) {
|
|
951 /*
|
|
952 * Panel gridPanel = new Panel(new GridLayout(0, 1)); Panel
|
|
953 * outerPanel = new Panel(new FlowLayout(FlowLayout.LEFT));
|
|
954 * outerPanel.add(gridPanel); vncContainer.setLayout(new
|
|
955 * FlowLayout(FlowLayout.LEFT, 30, 16));
|
|
956 * vncContainer.add(outerPanel); Panel textPanel = new Panel(new
|
|
957 * FlowLayout(FlowLayout.CENTER)); textPanel.add(errLabel);
|
|
958 * gridPanel.add(textPanel); gridPanel.add(new ReloginPanel(this));
|
|
959 */
|
|
960 } else {
|
|
961 /*
|
|
962 * vncContainer.setLayout(new FlowLayout(FlowLayout.LEFT, 30, 30));
|
|
963 * vncContainer.add(errLabel);
|
|
964 */
|
|
965 }
|
|
966
|
|
967 }
|
|
968
|
|
969 //
|
|
970 // Stop the applet.
|
|
971 // Main applet thread will terminate on first exception
|
|
972 // after seeing that rfbThread has been set to null.
|
|
973 //
|
|
974
|
|
975 public void stop() {
|
|
976 System.out.println("Stopping applet");
|
|
977 rfbThread = null;
|
|
978 }
|
|
979
|
|
980 //
|
|
981 // This method is called before the applet is destroyed.
|
|
982 //
|
|
983
|
|
984 public void destroy() {
|
|
985 System.out.println("Destroying applet");
|
|
986
|
|
987 vncContainer.removeAll();
|
|
988 // options.dispose();
|
|
989 clipboard.dispose();
|
|
990 if (rec != null)
|
|
991 rec.dispose();
|
|
992 if (rfb != null && !rfb.closed())
|
|
993 rfb.close();
|
|
994 }
|
|
995
|
|
996 //
|
|
997 // Start/stop receiving mouse events.
|
|
998 //
|
|
999
|
|
1000 public void enableInput(boolean enable) {
|
|
1001 vc.enableInput(enable);
|
|
1002 }
|
|
1003
|
|
1004 //
|
|
1005 // Close application properly on window close event.
|
|
1006 //
|
|
1007
|
|
1008 public void windowClosing(WindowEvent evt) {
|
|
1009 System.out.println("Closing window");
|
|
1010 if (rfb != null)
|
|
1011 disconnect();
|
|
1012
|
|
1013 vncContainer.hide();
|
|
1014
|
|
1015 }
|
|
1016
|
|
1017 //
|
|
1018 // Ignore window events we're not interested in.
|
|
1019 //
|
|
1020
|
|
1021 public void windowActivated(WindowEvent evt) {
|
|
1022 }
|
|
1023
|
|
1024 public void windowDeactivated(WindowEvent evt) {
|
|
1025 }
|
|
1026
|
|
1027 public void windowOpened(WindowEvent evt) {
|
|
1028 }
|
|
1029
|
|
1030 public void windowClosed(WindowEvent evt) {
|
|
1031 }
|
|
1032
|
|
1033 public void windowIconified(WindowEvent evt) {
|
|
1034 }
|
|
1035
|
|
1036 public void windowDeiconified(WindowEvent evt) {
|
|
1037 }
|
|
1038 }
|