Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Button ssh=new Button("SSH");
- viewgrid.add(ssh, 0, row+1);
- ssh.setOnAction(new EventHandler<ActionEvent>() {
- String string;
- @Override
- public void handle(ActionEvent event) {
- JSch jsch=new JSch();
- Dialog<ArrayList<String>> dialog2=new Dialog<>();
- dialog2.setTitle("Logging in");
- dialog2.setContentText("Write username, host and password");
- Label lun=new Label("Username");
- Label lh=new Label("Host");
- Label lp=new Label("Password");
- Label error=new Label();
- TextField tun=new TextField(System.getProperty("user.name"));
- TextField th=new TextField("localhost");
- TextField tp=new TextField();
- GridPane gp=new GridPane();
- gp.add(lun, 0, 0);
- gp.add(tun, 1, 0);
- gp.add(lh, 0, 1);
- gp.add(th, 1, 1);
- gp.add(lp, 0, 2);
- gp.add(tp, 1, 2);
- gp.add(error, 0, 3,2,1);
- gp.setVgap(6);
- gp.setHgap(6);
- // gp.setPadding(new Insets(6,0,0,0));
- DialogPane dialogPane=dialog2.getDialogPane();
- dialogPane.setContent(gp);
- ButtonType typeok=new ButtonType("Enter", ButtonData.OK_DONE);
- dialogPane.getButtonTypes().add(typeok);
- Button okbutton=(Button) dialogPane.lookupButton(typeok);
- okbutton.addEventFilter(ActionEvent.ACTION, ef->
- {
- if(tun.getText().equals("")|| th.getText().equals("")||
- tp.getText().equals(""))
- {
- error.setText("Not enough values");
- ef.consume();
- }
- });
- dialog2.setResultConverter(new Callback<ButtonType, ArrayList<String>>() {
- @Override
- public ArrayList<String> call(ButtonType param) {
- if(param==typeok) return new ArrayList<String>(Arrays.asList(tun.getText(),th.getText(),tp.getText()));
- return null;
- }
- });
- Optional<ArrayList<String>> result=dialog2.showAndWait();
- System.out.println(result);
- if(result.isPresent())
- {
- ArrayList<String> list=result.get();
- System.out.println(list);
- String user=list.get(0);
- String host=list.get(1);
- String password=list.get(2);
- //Seems to happen because of below
- try {
- Session session=jsch.getSession(user, host, 22);
- session.setPassword(password);
- session.setConfig("StrictHostKeyChecking", "no");//unsafe
- session.connect(3000);
- Channel channel=session.openChannel("shell");
- channel.setInputStream(System.in);
- channel.setOutputStream(System.out);
- channel.connect(3000);
- } catch (JSchException e) {
- e.printStackTrace();
- }
- }
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement