use of com.tigervnc.rfb.Exception in project tigervnc by TigerVNC.
the class CConn method clientRedirect.
// clientRedirect() migrates the client to another host/port
public void clientRedirect(int port, String host, String x509subject) {
try {
sock.close();
sock = new TcpSocket(host, port);
vlog.info("Redirected to " + host + ":" + port);
setServerName(host);
setServerPort(port);
sock.inStream().setBlockCallback(this);
setStreams(sock.inStream(), sock.outStream());
if (desktop != null)
desktop.dispose();
initialiseProtocol();
} catch (java.lang.Exception e) {
throw new Exception(e.getMessage());
}
}
use of com.tigervnc.rfb.Exception in project tigervnc by TigerVNC.
the class Tunnel method createTunnelExt.
private static void createTunnelExt(String gatewayHost, String remoteHost, int remotePort, int localPort, String pattern) throws Exception {
if (pattern == null || pattern.length() < 1) {
if (tunnel.getValue() && via.getValue().isEmpty())
pattern = DEFAULT_TUNNEL_TEMPLATE;
else
pattern = DEFAULT_VIA_TEMPLATE;
}
String cmd = fillCmdPattern(pattern, gatewayHost, remoteHost, remotePort, localPort);
try {
Thread t = new Thread(new ExtProcess(cmd, vlog, true));
t.start();
// wait for the ssh process to start
Thread.sleep(1000);
} catch (java.lang.Exception e) {
throw new Exception(e.getMessage());
}
}
use of com.tigervnc.rfb.Exception in project tigervnc by TigerVNC.
the class UserDialog method getUserPasswd.
public final void getUserPasswd(boolean secure, StringBuffer user, StringBuffer password) {
String passwordFileStr = passwordFile.getValue();
if ((password == null) && sendLocalUsername.getValue()) {
user.append((String) System.getProperties().get("user.name"));
return;
}
if (user == null && !passwordFileStr.equals("")) {
InputStream fp = null;
try {
fp = new FileInputStream(passwordFileStr);
} catch (FileNotFoundException e) {
throw new Exception("Opening password file failed");
}
byte[] obfPwd = new byte[256];
try {
fp.read(obfPwd);
fp.close();
} catch (IOException e) {
throw new Exception("Failed to read VncPasswd file");
}
String PlainPasswd = VncAuth.unobfuscatePasswd(obfPwd);
password.append(PlainPasswd);
password.setLength(PlainPasswd.length());
return;
}
JDialog win;
JLabel banner;
JTextField username = null;
JLayer icon;
int y;
JPanel msg = new JPanel(null);
msg.setSize(410, 145);
banner = new JLabel();
banner.setBounds(0, 0, msg.getPreferredSize().width, 20);
banner.setHorizontalAlignment(JLabel.CENTER);
banner.setOpaque(true);
if (secure) {
banner.setText("This connection is secure");
banner.setBackground(Color.GREEN);
ImageIcon secure_icon = new ImageIcon(VncViewer.class.getResource("secure.png"));
banner.setIcon(secure_icon);
} else {
banner.setText("This connection is not secure");
banner.setBackground(Color.RED);
ImageIcon insecure_icon = new ImageIcon(VncViewer.class.getResource("insecure.png"));
banner.setIcon(insecure_icon);
}
msg.add(banner);
y = 20 + 10;
JButton iconb = new JButton("?");
iconb.setVerticalAlignment(JLabel.CENTER);
iconb.setFont(new Font("Times", Font.BOLD, 34));
iconb.setForeground(Color.BLUE);
LayerUI ui = new MyLayerUI();
icon = new JLayer(iconb, ui);
icon.setBounds(10, y, 50, 50);
msg.add(icon);
y += 5;
if (user != null && !sendLocalUsername.getValue()) {
JLabel userLabel = new JLabel("Username:");
userLabel.setBounds(70, y, msg.getSize().width - 70 - 10, 20);
msg.add(userLabel);
y += 20 + 5;
username = new JTextField(30);
username.setBounds(70, y, msg.getSize().width - 70 - 10, 25);
msg.add(username);
y += 25 + 5;
}
JLabel passwdLabel = new JLabel("Password:");
passwdLabel.setBounds(70, y, msg.getSize().width - 70 - 10, 20);
msg.add(passwdLabel);
y += 20 + 5;
final JPasswordField passwd = new JPasswordField(30);
passwd.setBounds(70, y, msg.getSize().width - 70 - 10, 25);
msg.add(passwd);
y += 25 + 5;
msg.setPreferredSize(new Dimension(410, y));
Object[] options = { "OK \u21B5", "Cancel" };
JOptionPane pane = new JOptionPane(msg, PLAIN_MESSAGE, OK_CANCEL_OPTION, // do not use a custom Icon
null, // the titles of buttons
options, // default button title
options[0]) {
@Override
public void selectInitialValue() {
passwd.requestFocusInWindow();
}
};
pane.setBorder(new EmptyBorder(0, 0, 0, 0));
Component c = pane.getComponent(pane.getComponentCount() - 1);
((JComponent) c).setBorder(new EmptyBorder(0, 0, 10, 10));
win = pane.createDialog("VNC Authentication");
win.setVisible(true);
if (pane.getValue() == null || pane.getValue().equals("Cancel"))
throw new Exception("Authentication cancelled");
if (user != null)
if (sendLocalUsername.getValue())
user.append((String) System.getProperties().get("user.name"));
else
user.append(username.getText());
if (password != null)
password.append(new String(passwd.getPassword()));
}
use of com.tigervnc.rfb.Exception in project tigervnc by TigerVNC.
the class Viewport method handlePointerEvent.
private void handlePointerEvent(Point pos, int buttonMask) {
if (!viewOnly.getValue()) {
if (buttonMask != lastButtonMask || !pos.equals(lastPointerPos)) {
try {
if (cc.cp.width != scaledWidth || cc.cp.height != scaledHeight) {
int sx = (scaleRatioX == 1.00) ? pos.x : (int) Math.floor(pos.x / scaleRatioX);
int sy = (scaleRatioY == 1.00) ? pos.y : (int) Math.floor(pos.y / scaleRatioY);
pos = pos.translate(new Point(sx - pos.x, sy - pos.y));
}
cc.writer().pointerEvent(pos, buttonMask);
} catch (Exception e) {
vlog.error("%s", e.getMessage());
cc.close();
}
}
lastPointerPos = pos;
lastButtonMask = buttonMask;
}
}
Aggregations