Advertisement
Guest User

Untitled

a guest
Jun 26th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.39 KB | None | 0 0
  1. Button ssh=new Button("SSH");
  2. viewgrid.add(ssh, 0, row+1);
  3. ssh.setOnAction(new EventHandler<ActionEvent>() {
  4. String string;
  5. @Override
  6. public void handle(ActionEvent event) {
  7. JSch jsch=new JSch();
  8. Dialog<ArrayList<String>> dialog2=new Dialog<>();
  9. dialog2.setTitle("Logging in");
  10. dialog2.setContentText("Write username, host and password");
  11. Label lun=new Label("Username");
  12. Label lh=new Label("Host");
  13. Label lp=new Label("Password");
  14. Label error=new Label();
  15. TextField tun=new TextField(System.getProperty("user.name"));
  16. TextField th=new TextField("localhost");
  17. TextField tp=new TextField();
  18. GridPane gp=new GridPane();
  19. gp.add(lun, 0, 0);
  20. gp.add(tun, 1, 0);
  21. gp.add(lh, 0, 1);
  22. gp.add(th, 1, 1);
  23. gp.add(lp, 0, 2);
  24. gp.add(tp, 1, 2);
  25. gp.add(error, 0, 3,2,1);
  26. gp.setVgap(6);
  27. gp.setHgap(6);
  28. // gp.setPadding(new Insets(6,0,0,0));
  29. DialogPane dialogPane=dialog2.getDialogPane();
  30. dialogPane.setContent(gp);
  31. ButtonType typeok=new ButtonType("Enter", ButtonData.OK_DONE);
  32. dialogPane.getButtonTypes().add(typeok);
  33. Button okbutton=(Button) dialogPane.lookupButton(typeok);
  34. okbutton.addEventFilter(ActionEvent.ACTION, ef->
  35. {
  36. if(tun.getText().equals("")|| th.getText().equals("")||
  37. tp.getText().equals(""))
  38. {
  39. error.setText("Not enough values");
  40. ef.consume();
  41. }
  42. });
  43. dialog2.setResultConverter(new Callback<ButtonType, ArrayList<String>>() {
  44. @Override
  45. public ArrayList<String> call(ButtonType param) {
  46. if(param==typeok) return new ArrayList<String>(Arrays.asList(tun.getText(),th.getText(),tp.getText()));
  47. return null;
  48. }
  49. });
  50. Optional<ArrayList<String>> result=dialog2.showAndWait();
  51. System.out.println(result);
  52. if(result.isPresent())
  53. {
  54. ArrayList<String> list=result.get();
  55. System.out.println(list);
  56. String user=list.get(0);
  57. String host=list.get(1);
  58. String password=list.get(2);
  59. //Seems to happen because of below
  60. try {
  61. Session session=jsch.getSession(user, host, 22);
  62. session.setPassword(password);
  63. session.setConfig("StrictHostKeyChecking", "no");//unsafe
  64. session.connect(3000);
  65. Channel channel=session.openChannel("shell");
  66. channel.setInputStream(System.in);
  67. channel.setOutputStream(System.out);
  68. channel.connect(3000);
  69. } catch (JSchException e) {
  70. e.printStackTrace();
  71. }
  72. }
  73. }
  74. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement