return new Path(DEVICE_SSH_DIR).append(filename).toString();\r
}\r
\r
- public static void registerAuthorizedKey(String publicKey) {\r
+ public static boolean registerAuthorizedKey(String publicKey) {\r
+ try {\r
+ FileReader fileReader = new FileReader(publicKey);\r
+ BufferedReader reader = new BufferedReader(fileReader);\r
+ String pubkey = reader.readLine();\r
+ IRemoteExecutionTools exectool = RemoteConnectionManager.getRemoteTools().getExecTool();\r
+ IRemoteFileTools filetool = RemoteConnectionManager.getRemoteTools().getFileTool();\r
+ String userhome = RemoteConnectionManager.getRemoteTools().getUserhome();\r
+ IPath remoteSshPath = new Path(userhome).append(".ssh");\r
+ String remoteAuthfile = remoteSshPath.append("authorized_keys").toString();\r
+ filetool.assureDirectory(remoteSshPath.toString(), new NullProgressMonitor());\r
+ String cmd = String.format("echo \"%s\" >> %s", pubkey, remoteAuthfile);\r
+ exectool.executeBashCommand(cmd);\r
+ if (!isSetAuthorizedKey(publicKey)) {\r
+ return false;\r
+ }\r
+ } catch (Exception e) {\r
+ e.printStackTrace();\r
+ logger.error("Failed to register authorized key", e);\r
+ }\r
+ return true;\r
+ }\r
+ \r
+ public static boolean isSetAuthorizedKey(String publicKey) {\r
+ boolean isSet = false;\r
try {\r
FileReader fileReader = new FileReader(publicKey);\r
BufferedReader reader = new BufferedReader(fileReader);\r
String userhome = RemoteConnectionManager.getRemoteTools().getUserhome();\r
IPath remoteSshPath = new Path(userhome).append(".ssh");\r
String remoteAuthfile = remoteSshPath.append("authorized_keys").toString();\r
- boolean needSet = true;\r
if (filetool.hasFile(remoteAuthfile, new NullProgressMonitor())) {\r
String cmd = String.format("grep -rn \"%s\" %s", pubkey, remoteAuthfile);\r
String output = exectool.executeWithOutput(cmd);\r
if (!output.isEmpty()) {\r
- needSet = false;\r
+ isSet = true;\r
}\r
}\r
- if (needSet) {\r
- filetool.assureDirectory(remoteSshPath.toString(), new NullProgressMonitor());\r
- String cmd = String.format("echo \"%s\" >> %s", pubkey, remoteAuthfile);\r
- exectool.executeBashCommand(cmd);\r
- }\r
} catch (Exception e) {\r
e.printStackTrace();\r
- logger.error("Failed to register authorized key%s]", e);\r
+ logger.error("Failed to check authorized key", e);\r
}\r
+ return isSet;\r
}\r
}\r
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Text;
import org.tizen.common.util.DialogUtil;
import org.tizen.common.util.log.UserLogger;
-import org.tizen.nativeplatform.preferences.PreferencesManager;
import org.tizen.nativeplatform.preferences.RemoteServerPreferencesManager;
import org.tizen.nativeplatform.remote.connection.RemoteConnectionManager;
import org.tizen.nativeplatform.util.PlatformUserInteraction;
private int x = 0;
private int y = 0;
private int width = 400;
- private int height = 250;
-
+ private int height = 300;
+
private boolean connected = false;
private final String BUNDLE_NAME = RemoteConnectionDialog.class.getPackage().getName()
@Override
protected void createButtonsForButtonBar(Composite parent) {
super.createButtonsForButtonBar(parent);
-
+
Button ok = getButton(IDialogConstants.OK_ID);
ok.setText("Connect");
setButtonLayoutData(ok);
| GridData.VERTICAL_ALIGN_BEGINNING));
composite.setLayout(new GridLayout(1, false));
+ createGuideComposite(composite);
createConnectionComposite(composite);
createSshComposite(composite);
return null;
}
-
+
private void createSshComposite(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(new GridLayout(3, false));
gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.minimumHeight = 0;
-
+
Label sshPrivate = new Label(composite, SWT.NONE);
sshPrivate.setText("SSH Private key:");
sshPrivateText = new Text(composite, SWT.SINGLE | SWT.BORDER | SWT.READ_ONLY);
}
});
}
-
+
+ private void createGuideComposite(Composite parent) {
+ Composite comp_descrip = new Composite(parent, SWT.NONE | SWT.BORDER);
+ Color whiteColor = new Color(parent.getDisplay(), 255, 255, 255);
+ comp_descrip.setLayout(new GridLayout(1, false));
+ GridData comp_descrip_gd = new GridData(GridData.FILL_HORIZONTAL);
+ comp_descrip_gd.heightHint = 40;
+ comp_descrip.setLayoutData(comp_descrip_gd);
+ comp_descrip.setBackground(whiteColor);
+ Label label = new Label(comp_descrip, SWT.WRAP);
+ label.setText(resources.getString("RemoteConDlg.HeadlineGuide"));
+ label.setBackground(whiteColor);
+ }
+
private String getDefaultSshPrivateKey() {
String home = System.getProperty("user.home");
IPath path = new Path(home).append(".ssh").append("id_rsa");
return "";
}
}
-
-
+
private String getDefaultSshPublicKey() {
String home = System.getProperty("user.home");
IPath path = new Path(home).append(".ssh").append("id_rsa.pub");
return "";
}
}
+
private void createConnectionComposite(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(new GridLayout(2, false));
GridData gridData = new GridData(GridData.FILL_BOTH);
composite.setLayoutData(gridData);
-
+
gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.minimumHeight = 0;
-
+
Label hostLabel = new Label(composite, SWT.NONE);
hostLabel.setText("Host:");
hostText = new Text(composite, SWT.SINGLE | SWT.BORDER);
passwordLabel.setText("Password:");
passText = new Text(composite, SWT.SINGLE | SWT.BORDER | SWT.PASSWORD);
passText.setLayoutData(gridData);
- //passText.setText(PreferencesManager.getRemoteServerPasswd());
+ // passText.setText(PreferencesManager.getRemoteServerPasswd());
}
public boolean connected() {
- return connected;
+ return connected;
}
@Override
final String pass = passText.getText();
final String privateKey = sshPrivateText.getText();
final String publicKey = sshPublicText.getText();
-
- boolean isNotOk = host.isEmpty() || user.isEmpty() || pass.isEmpty()
- || privateKey.isEmpty() || publicKey.isEmpty();
-
+
+ boolean isNotOk = host.isEmpty() || user.isEmpty() || pass.isEmpty()
+ || privateKey.isEmpty() || publicKey.isEmpty();
+
if (isNotOk) {
DialogUtil.openErrorDialog("Please input all connection information.");
return;
}
-
+
ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
try {
dialog.run(true, true, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException,
- InterruptedException {
- monitor.beginTask(resources.getString("RemoteConnDlg.Progress.Creating"), 1);
- try {
- UserLogger.start(PlatformUserInteraction.CONNECT_SSH);
- connected = RemoteConnectionManager.createConnection(host, user, pass, publicKey, privateKey,
- new SubProgressMonitor(monitor, 1));
- UserLogger.end(PlatformUserInteraction.CONNECT_SSH);
- if (!connected) {
- DialogUtil.openMessageDialog(getShell(), "Failed to connect");
- } else {
- SSHUtil.registerAuthorizedKey(publicKey);
- }
- } finally {
- monitor.done();
- }
+ InterruptedException {
+ monitor.beginTask(resources.getString("RemoteConnDlg.Progress.Creating"), 1);
+ try {
+ UserLogger.start(PlatformUserInteraction.CONNECT_SSH);
+ connected = RemoteConnectionManager.createConnection(host, user, pass,
+ publicKey, privateKey, new SubProgressMonitor(monitor, 1));
+ UserLogger.end(PlatformUserInteraction.CONNECT_SSH);
+ if (!connected) {
+ DialogUtil.openMessageDialog(getShell(), "Failed to connect");
+ } else {
+ if (!SSHUtil.isSetAuthorizedKey(publicKey)) {
+ if (SSHUtil.registerAuthorizedKey(publicKey)) {
+ DialogUtil
+ .openMessageDialog(getShell(),
+ "Your public key registration has been sucessfully sent");
+ } else {
+ DialogUtil.openErrorDialog(getShell(), "Error",
+ "Failed to register public key");
+ }
+ }
+ }
+ } finally {
+ monitor.done();
+ }
}
- });
- } catch (Exception e) {
- return;
- }
-
- super.okPressed();
+ });
+ } catch (Exception e) {
+ return;
+ }
+
+ super.okPressed();
}
}