Mercurial > hg > Members > nobuyasu > tightVNCProxy
comparison src/myVncProxy/VncProxyService.java @ 184:134deb9f8148
update
author | one |
---|---|
date | Mon, 07 Nov 2011 12:41:16 +0900 |
parents | da276538c1d5 |
children | 950ffe24f72e |
comparison
equal
deleted
inserted
replaced
181:f0dc6e6e85dc | 184:134deb9f8148 |
---|---|
4 import java.awt.event.*; | 4 import java.awt.event.*; |
5 import java.io.*; | 5 import java.io.*; |
6 import java.net.*; | 6 import java.net.*; |
7 | 7 |
8 public class VncProxyService implements java.lang.Runnable { | 8 public class VncProxyService implements java.lang.Runnable { |
9 | |
9 | 10 |
10 public static void main(String[] argv) { | 11 public static void main(String[] argv) { |
11 VncProxyService v = new VncProxyService(); | 12 VncProxyService v = new VncProxyService(); |
12 | 13 |
13 // v.checkArgs(argv); | 14 // v.checkArgs(argv); |
23 | 24 |
24 CreateHtmlFile hgtmlFile; | 25 CreateHtmlFile hgtmlFile; |
25 | 26 |
26 // RfbProto rfb; | 27 // RfbProto rfb; |
27 MyRfbProto rfb; | 28 MyRfbProto rfb; |
29 MyRfbProto testrfb; | |
28 Thread rfbThread; | 30 Thread rfbThread; |
29 Thread accThread; | 31 Thread accThread; |
30 Thread clientThread; | 32 Thread clientThread; |
31 CreateThread geth; | 33 CreateThread geth; |
32 AcceptClient acc; | 34 AcceptClient acc; |
35 private AcceptThread acceptThread; | |
33 private TextBox getHost; | 36 private TextBox getHost; |
34 | 37 |
35 Frame vncFrame; | 38 Frame vncFrame; |
36 Container vncContainer; | 39 Container vncContainer; |
37 ScrollPane desktopScrollPane; | 40 ScrollPane desktopScrollPane; |
65 int deferUpdateRequests; | 68 int deferUpdateRequests; |
66 int debugStatsExcludeUpdates; | 69 int debugStatsExcludeUpdates; |
67 int debugStatsMeasureUpdates; | 70 int debugStatsMeasureUpdates; |
68 | 71 |
69 int echoPort = 9999; | 72 int echoPort = 9999; |
73 private boolean changeFlag; | |
70 | 74 |
71 String url; | 75 String url; |
72 | 76 |
73 // XmlRpc client; | 77 // XmlRpc client; |
74 String wpUsername, wpPassword, blogId; | 78 String wpUsername, wpPassword, blogId; |
119 // | 123 // |
120 // init() | 124 // init() |
121 // | 125 // |
122 | 126 |
123 public void init() { | 127 public void init() { |
124 | 128 |
125 readParameters(); | 129 readParameters(); |
126 | 130 |
127 options = new OptionsNoFrame(this); | 131 options = new OptionsNoFrame(this); |
128 recordingSync = new Object(); | 132 recordingSync = new Object(); |
129 | 133 |
146 } catch (IOException e) { | 150 } catch (IOException e) { |
147 fatalError("Network error: faild connect or authenticate to server"); | 151 fatalError("Network error: faild connect or authenticate to server"); |
148 } catch (Exception e) { | 152 } catch (Exception e) { |
149 | 153 |
150 } | 154 } |
151 | 155 /* |
152 rfb.selectPort(5999); | 156 if(changeFlag){ |
153 rfbThread = new Thread(this); | 157 acceptThread.changeRfb(rfb); |
154 accThread = new Thread(new AcceptThread(rfb, 5999)); | 158 } else {*/ |
155 | 159 rfb.selectPort(5999); |
160 rfbThread = new Thread(this); | |
161 acceptThread = new AcceptThread(rfb, 5999); | |
162 accThread = new Thread(acceptThread); | |
163 //} | |
156 /* | 164 /* |
157 * if(url != null) { try { client = new XmlRpc(blogId, wpUsername, | 165 * if(url != null) { try { client = new XmlRpc(blogId, wpUsername, |
158 * wpPassword, url ); InetAddress addr = InetAddress.getLocalHost(); | 166 * wpPassword, url ); InetAddress addr = InetAddress.getLocalHost(); |
159 * String add = new String(addr.getHostAddress()); | 167 * String add = new String(addr.getHostAddress()); |
160 * client.addDescription(rfb.desktopName); setStatusXmlRpc(client, | 168 * client.addDescription(rfb.desktopName); setStatusXmlRpc(client, |
165 * e.printStackTrace(); } catch (UnknownHostException e) { | 173 * e.printStackTrace(); } catch (UnknownHostException e) { |
166 * e.printStackTrace(); } } | 174 * e.printStackTrace(); } } |
167 */ | 175 */ |
168 | 176 |
169 } | 177 } |
178 | |
179 | |
180 public void changeInit() throws Exception { | |
181 VncProxyService v = new VncProxyService(); | |
182 v.changeFlag = true; | |
183 // v.checkArgs(argv); | |
184 | |
185 v.mainArgs = new String[0]; | |
186 v.host = host; | |
187 v.init(); | |
188 v.start_threads(); | |
189 | |
190 //Thread.sleep(10000); | |
191 rfb.is = v.rfb.is; | |
192 //rfb.os = v.rfb.os; | |
193 //rfb.initData = v.rfb.initData; | |
194 | |
195 // changeConnection(); | |
196 // doProtocolInitialisation(); | |
197 /* | |
198 //readParameters(); | |
199 options = new OptionsNoFrame(this); | |
200 recordingSync = new Object(); | |
201 | |
202 sessionFileName = null; | |
203 recordingActive = false; | |
204 recordingStatusChanged = false; | |
205 cursorUpdatesDef = null; | |
206 eightBitColorsDef = null; | |
207 | |
208 try { | |
209 changeConnection(); | |
210 doProtocolInitialisation(); | |
211 } catch (NoRouteToHostException e) { | |
212 fatalError("Network error: no route to server: " + host, e); | |
213 } catch (UnknownHostException e) { | |
214 fatalError("Network error: server name unknown: " + host, e); | |
215 } catch (ConnectException e) { | |
216 fatalError("Network error: could not connect to server: " + host | |
217 + ":" + port, e); | |
218 } catch (IOException e) { | |
219 fatalError("Network error: faild connect or authenticate to server"); | |
220 } catch (Exception e) { | |
221 | |
222 } | |
223 | |
224 //acceptThread.changeRfb(rfb); | |
225 //vc.rfb = rfb; | |
226 //rfbThread.start(); | |
227 */ | |
228 } | |
170 | 229 |
171 /* | 230 /* |
172 * void setStatusXmlRpc(XmlRpc client, String title, String hostname, int | 231 * void setStatusXmlRpc(XmlRpc client, String title, String hostname, int |
173 * port) { client.setTitle(title); String description = | 232 * port) { client.setTitle(title); String description = |
174 * makeDescription(hostname, Integer.toString(port)); | 233 * makeDescription(hostname, Integer.toString(port)); |
176 */ | 235 */ |
177 String makeDescription(String hostname, String port) { | 236 String makeDescription(String hostname, String port) { |
178 String description = "<h1>" + hostname + " " + port + "<h1>\n"; | 237 String description = "<h1>" + hostname + " " + port + "<h1>\n"; |
179 return description; | 238 return description; |
180 } | 239 } |
181 | 240 |
182 public void start_threads() { | 241 public void start_threads() { |
183 rfbThread.start(); | 242 rfbThread.start(); |
184 accThread.start(); | 243 accThread.start(); |
185 rfb.requestThreadStart(); | 244 rfb.requestThreadStart(); |
186 | |
187 } | 245 } |
188 | 246 |
189 // | 247 // |
190 // run() - executed by the rfbThread to deal with the RFB socket. | 248 // run() - executed by the rfbThread to deal with the RFB socket. |
191 // | 249 // |
192 | |
193 public void run() { | 250 public void run() { |
194 | 251 |
195 try { | 252 try { |
196 // connectAndAuthenticate(); | 253 // connectAndAuthenticate(); |
197 // doProtocolInitialisation(); | 254 // doProtocolInitialisation(); |
268 // Connect to the RFB server and authenticate the user. | 325 // Connect to the RFB server and authenticate the user. |
269 // | 326 // |
270 | 327 |
271 void connectAndAuthenticate() throws Exception { | 328 void connectAndAuthenticate() throws Exception { |
272 if (mainArgs.length == 0) | 329 if (mainArgs.length == 0) |
273 acc = new AcceptClient(getHost.getAddress()); | 330 acc = new AcceptClient(host); |
331 //acc = new AcceptClient(getHost.getAddress()); | |
274 // acc = new AcceptClient(); | 332 // acc = new AcceptClient(); |
275 else | 333 else |
276 acc = new AcceptClient(mainArgs[0]); | 334 acc = new AcceptClient(mainArgs[0]); |
277 geth = new CreateThread(acc, echoPort); | 335 geth = new CreateThread(acc, echoPort); |
278 Thread thread = new Thread(geth); | 336 Thread thread = new Thread(geth); |
323 } | 381 } |
324 break; | 382 break; |
325 default: | 383 default: |
326 throw new Exception("Unknown authentication scheme " + authType); | 384 throw new Exception("Unknown authentication scheme " + authType); |
327 } | 385 } |
386 } | |
387 | |
388 void changeConnection() throws Exception { | |
389 /* | |
390 acc = new AcceptClient(getHost.getAddress()); | |
391 geth = new CreateThread(acc, echoPort); | |
392 Thread thread = new Thread(geth); | |
393 thread.start(); | |
394 */ | |
395 showConnectionStatus("Initializing..."); | |
396 | |
397 showConnectionStatus("Connecting to " + host + ", port " + port + "..."); | |
398 | |
399 //rfb = null; | |
400 //rfb.is = null; | |
401 | |
402 testrfb = new MyRfbProto(host, port); | |
403 showConnectionStatus("Connected to server"); | |
404 | |
405 testrfb.readVersionMsg(); | |
406 showConnectionStatus("RFB server supports protocol version " | |
407 + testrfb.serverMajor + "." + testrfb.serverMinor); | |
408 | |
409 testrfb.writeVersionMsg(); | |
410 showConnectionStatus("Using RFB protocol version " + testrfb.clientMajor | |
411 + "." + testrfb.clientMinor); | |
412 | |
413 int secType = testrfb.negotiateSecurity(); | |
414 int authType; | |
415 if (secType == RfbProto.SecTypeTight) { | |
416 showConnectionStatus("Enabling TightVNC protocol extensions"); | |
417 testrfb.setupTunneling(); | |
418 authType = testrfb.negotiateAuthenticationTight(); | |
419 } else { | |
420 authType = secType; | |
421 } | |
422 | |
423 switch (authType) { | |
424 case MyRfbProto.AuthAccess: | |
425 testrfb.authenticationRequestAccess(); | |
426 System.out.println("authenticateion Request right of Acces"); | |
427 break; | |
428 case RfbProto.AuthNone: | |
429 showConnectionStatus("No authentication needed"); | |
430 testrfb.authenticateNone(); | |
431 break; | |
432 case RfbProto.AuthVNC: | |
433 showConnectionStatus("Performing standard VNC authentication"); | |
434 if (passwordParam != null) { | |
435 testrfb.authenticateVNC(passwordParam); | |
436 } else { | |
437 String pw = askPassword(); | |
438 testrfb.authenticateVNC(pw); | |
439 } | |
440 break; | |
441 default: | |
442 throw new Exception("Unknown authentication scheme " + authType); | |
443 } | |
444 rfb.is = testrfb.is; | |
445 rfb.os = testrfb.os; | |
446 //rfb = testrfb; | |
328 } | 447 } |
329 | 448 |
330 // | 449 // |
331 // Show a message describing the connection status. | 450 // Show a message describing the connection status. |
332 // To hide the connection status label, use (msg == null). | 451 // To hide the connection status label, use (msg == null). |
599 // readParameters() - read parameters from the html source or from the | 718 // readParameters() - read parameters from the html source or from the |
600 // command line. On the command line, the arguments are just a sequence of | 719 // command line. On the command line, the arguments are just a sequence of |
601 // param_name/param_value pairs where the names and values correspond to | 720 // param_name/param_value pairs where the names and values correspond to |
602 // those expected in the html applet tag source. | 721 // those expected in the html applet tag source. |
603 // | 722 // |
604 | 723 |
605 void readParameters() { | 724 void readParameters() { |
606 if (mainArgs.length == 0) { | 725 if (!(changeFlag)) { |
607 getHost = new TextBox(); | 726 if (mainArgs.length == 0) { |
608 getHost.ipRegister(); | 727 getHost = new TextBox(this); |
609 host = getHost.getAddress(); | 728 getHost.ipRegister(); |
729 host = getHost.getAddress(); | |
730 } else { | |
731 host = mainArgs[0]; | |
732 } | |
733 | |
734 if (mainArgs.length < 2) { | |
735 port = Integer.parseInt(getHost.getPort()); | |
736 // port = 5900; | |
737 } else { | |
738 port = Integer.parseInt(mainArgs[1]); | |
739 } | |
610 } else { | 740 } else { |
611 host = mainArgs[0]; | 741 getHost = new TextBox(this); |
612 } | 742 port = 5900; |
613 | 743 } |
614 if (mainArgs.length < 2) { | 744 |
615 port = Integer.parseInt(getHost.getPort()); | 745 getHost.changeHost(); |
616 // port = 5900; | |
617 } else { | |
618 port = Integer.parseInt(mainArgs[1]); | |
619 } | |
620 | 746 |
621 // Read "ENCPASSWORD" or "PASSWORD" parameter if specified. | 747 // Read "ENCPASSWORD" or "PASSWORD" parameter if specified. |
622 // readPasswordParameters(); | 748 // readPasswordParameters(); |
623 | 749 |
624 String str; | 750 String str; |
691 | 817 |
692 } | 818 } |
693 } | 819 } |
694 | 820 |
695 public String readParameter(String name, boolean required) { | 821 public String readParameter(String name, boolean required) { |
696 for (int i = 0; i < mainArgs.length; i += 2) { | 822 if(mainArgs!=null){ |
697 if (mainArgs[i].equalsIgnoreCase(name)) { | 823 for (int i = 0; i < mainArgs.length; i += 2) { |
698 try { | 824 if (mainArgs[i].equalsIgnoreCase(name)) { |
699 return mainArgs[i + 1]; | 825 try { |
700 } catch (Exception e) { | 826 return mainArgs[i + 1]; |
701 if (required) { | 827 } catch (Exception e) { |
702 fatalError(name + " parameter not specified"); | 828 if (required) { |
829 fatalError(name + " parameter not specified"); | |
830 } | |
831 return null; | |
703 } | 832 } |
704 return null; | |
705 } | 833 } |
706 } | 834 } |
707 } | 835 if (required) { |
708 if (required) { | 836 fatalError(name + " parameter not specified"); |
709 fatalError(name + " parameter not specified"); | 837 } |
710 } | 838 } |
711 return null; | 839 return null; |
712 } | 840 } |
713 | 841 |
714 int readIntParameter(String name, int defaultValue) { | 842 int readIntParameter(String name, int defaultValue) { |