/src/com/gmail/ianspigeon/applauncher/launchers/SSHClientLauncher.java

https://bitbucket.org/ianspigeon/applauncher · Java · 37 lines · 22 code · 14 blank · 1 comment · 4 complexity · 428f020ac37f7efebca15b0fd1690f0e MD5 · raw file

  1. package com.gmail.ianspigeon.applauncher.launchers;
  2. public class SSHClientLauncher extends Launcher {
  3. public String launch(String hostname, String port, String username) {
  4. System.out.println("SSHClientLauncher call detected." );
  5. try {
  6. validateParameter("hostname", hostname, "^[\\w.\\-_]+$");
  7. validateParameter("port", port, "^[\\d]+$");
  8. } catch (Exception e) {
  9. return e.getMessage();
  10. }
  11. if (isWindows()) {
  12. return executeWindowsCommand(new String[] {"C:\\Program Files\\PuTTY\\putty.exe",
  13. "-ssh", "-P", port, hostname, "-l", username});
  14. } else if (isLinux()) {
  15. // Run ssh with gnome-terminal
  16. return executeLinuxCommand(new String[] {"/usr/bin/gnome-terminal",
  17. "-x", "bash", "-c", "ssh -o 'StrictHostKeyChecking no' -p " +
  18. port + " -l '" + username + "' " + hostname + "; read"});
  19. } else {
  20. return "Unsupported platform, requires Windows or Linux.";
  21. }
  22. }
  23. }