public void closeConnection() { maintainConnection = false; if (keyboard != null) { // Tell the server to release any meta keys. keyboard.clearMetaState(); keyboard.processLocalKeyEvent(0, new KeyEvent(KeyEvent.ACTION_UP, 0)); } // Close the rfb connection. if (rfbconn != null) rfbconn.close(); // rfbconn = null; // rfb = null; // cc = null; // sock = null; // Close the SSH tunnel. if (sshConnection != null) { sshConnection.terminateSSHTunnel(); sshConnection = null; } onDestroy(); }
/** * Sets up connection to a given CVS root including any proxies on route. * * @param cvsRoot root to connect to * @return Connection object ready to connect to the given CVS root * @throws IllegalArgumentException if the 'method' part of the supplied CVS Root is not * recognized */ public static Connection setupConnection(CVSRoot cvsRoot) throws IllegalArgumentException { // for testing porposes allow to use dynamically generated port numbers String t9yRoot = System.getProperty("netbeans.t9y.cvs.connection.CVSROOT"); // NOI18N CVSRoot patchedCvsRoot = cvsRoot; if (t9yRoot != null && t9yRoot.length() > 0) { int idx = t9yRoot.indexOf(','); if (idx != -1) { System.setProperty( "netbeans.t9y.cvs.connection.CVSROOT", t9yRoot.substring(idx + 1)); // NOI18N t9yRoot = t9yRoot.substring(0, idx); } try { patchedCvsRoot = CVSRoot.parse(t9yRoot); assert patchedCvsRoot.getRepository().equals(cvsRoot.getRepository()); assert patchedCvsRoot.getHostName() == cvsRoot.getHostName() || patchedCvsRoot.getHostName().equals(cvsRoot.getHostName()); ErrorManager.getDefault() .log( ErrorManager.INFORMATIONAL, "CVS.ClientRuntime: using patched CVSROOT " + t9yRoot); // NOI18N } catch (IllegalArgumentException ex) { ErrorManager.getDefault().annotate(ex, "While parsing: " + t9yRoot); // NOI18N ErrorManager.getDefault().notify(ex); } } if (cvsRoot.isLocal()) { LocalConnection con = new LocalConnection(); con.setRepository(cvsRoot.getRepository()); return con; } ProxySocketFactory factory = ProxySocketFactory.getDefault(); String method = cvsRoot.getMethod(); if (CVSRoot.METHOD_PSERVER.equals(method)) { PServerConnection con = new PServerConnection(patchedCvsRoot, factory); char[] passwordChars = KeyringSupport.read(CvsModuleConfig.PREFIX_KEYRING_KEY, cvsRoot.toString()); String password; if (passwordChars != null) { password = new String(passwordChars); } else { password = PasswordsFile.findPassword(cvsRoot.toString()); if (password != null) { KeyringSupport.save( CvsModuleConfig.PREFIX_KEYRING_KEY, cvsRoot.toString(), password.toCharArray(), null); } } con.setEncodedPassword(password); return con; } else if (CVSRoot.METHOD_EXT.equals(method)) { CvsModuleConfig.ExtSettings extSettings = CvsModuleConfig.getDefault().getExtSettingsFor(cvsRoot); String userName = cvsRoot.getUserName(); String host = cvsRoot.getHostName(); if (extSettings.extUseInternalSsh) { int port = patchedCvsRoot.getPort(); port = port == 0 ? 22 : port; // default port String password = new String(extSettings.extPassword); if (password == null) { password = "******"; // NOI18N user will be asked later on } SSHConnection sshConnection = new SSHConnection(factory, host, port, userName, password); sshConnection.setRepository(cvsRoot.getRepository()); return sshConnection; } else { // What do we want to achieve here? // It's possible to mimics ordinary cvs or cvsnt behaviour: // Ordinary cvs style (CVS_RSH): // command += " $hostname [-l$username] $CVS_SERVER" // cvsnt style (CVS_EXT and CVS_RSH): // command += " cvs server" // I prefer the cvs style, see issue #62683 for details. String command = extSettings.extCommand; String cvs_server = System.getenv("CVS_SERVER"); cvs_server = cvs_server != null ? cvs_server + " server" : "cvs server"; // NOI18N String userOption = ""; // NOI18N if (userName != null) { userOption = " -l " + userName; // NOI18N } command += " " + host + userOption + " " + cvs_server; // NOI18N ExtConnection connection = new ExtConnection(command); connection.setRepository(cvsRoot.getRepository()); return connection; } } throw new IllegalArgumentException("Unrecognized CVS Root: " + cvsRoot); // NOI18N }
/** * Initializes SSH Tunnel and returns local forwarded port, or if SSH connection not needed, * returns saved plain VNC port. * * @return * @throws Exception */ int getVNCPort() throws Exception { if (connection.getConnectionType() == VncConstants.CONN_TYPE_SSH) { sshConnection = new SSHConnection(connection); return sshConnection.initializeSSHTunnel(); } else return connection.getPort(); }