Galera seguinte, eu estou tentando criar um terminal para connectar com meu servidor linux.
Pelo programa PUTTY eu consigo connectar normalmente…
Estou usando ese dialog:
http://www.primefaces.org/showcase/ui/terminalDialog.jsf
Está aparecendo o seguinte erro
prime $ ssh root@localhost
stdin: is not a tty
usage: ssh [-1246AaCfgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec]
[-D [bind_address:]port] [-e escape_char] [-F configfile]
[-i identity_file] [-L [bind_address:]port:host:hostport]
[-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port]
[-R [bind_address:]port:host:hostport] [-S ctl_path]
[-w local_tun[:remote_tun]] [user@]hostname [command]
Eu tenho 2 classes no meu código.
Uma delas eh a SSHConnector:
[code]package com.java.ssh;
//imports omitidos
public class SSHConector {
private Connection sshConnection;
private Session sshSession;
private String user;
private String password;
private InputStream stdout;
private InputStream stderr;
private OutputStream stdin;
private int state = 0; //0=stopped, 1=started
public SSHConector(String host, String user, String password) {
sshConnection = new Connection(host);
this.user = user;
this.password = password;
this.state = 0;
}
public void start() {
try {
sshConnection.connect();
boolean isAuthenticated = sshConnection.authenticateWithPassword(user, password);
if (isAuthenticated == false)
throw new IOException("Authentication failed.");
sshSession = sshConnection.openSession();
sshSession.startShell();
stdout = new StreamGobbler(sshSession.getStdout());
stderr = new StreamGobbler(sshSession.getStderr());
stdin = sshSession.getStdin();
read(); //consume login message
this.state = 1;
} catch (IOException e) {
// TODO Auto-generated catch block
this.state = 0;
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
this.state = 0;
e.printStackTrace();
}
}
public String read() throws IOException, InterruptedException{
BufferedReader br = new BufferedReader(new InputStreamReader(stdout));
StringBuffer sb = new StringBuffer();
sshSession.waitForCondition(ChannelCondition.EOF, 5000);
while (br.ready())
{
String line = br.readLine();
sb.append(line + "<BR>");
}
return sb.toString();
}
public String readError() throws IOException, InterruptedException{
BufferedReader br = new BufferedReader(new InputStreamReader(stderr));
StringBuffer sb = new StringBuffer();
sshSession.waitForCondition(ChannelCondition.EOF, 5000);
while (br.ready())
{
String line = br.readLine();
sb.append(line + "<BR>");
}
return sb.toString();
}
public void write(String message){
PrintStream ps = new PrintStream(stdin);
ps.println(message);
ps.flush();
}
public void stop() {
sshSession.close();
this.state = 0;
}
public String execCommand(String command){
String msg = "NO_ANSWER";
if (state == 0)
start();
try {
write(command);
msg = read();
if (msg.length() <= 0)
msg = readError();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
return msg;
}
}
[/code]
A outra eh a SshBean que faz a comunicação com a visão:
[code]package com.java.ssh;
//omitido os imports
@ManagedBean
public class SshBean {
//1- host, 2- login, 3- senha...
// na verdade nao eh local, mais obviamente nao vou por host, user e pass aki ^^
private SSHConector sshc = new SSHConector(“localhost”, “root”, “root”);
public SshBean() {
}
public String handleCommand(String command, String[] params) {
return sshc.execCommand(command);
}
}
[/code]
E na minha visão eu tenho o seguinte:
<p:dialog widgetVar="terminal" height="400" width="850" header="Terminal" resizable="false" modal="true">
<p:terminal widgetVar="term" commandHandler="#{sshBean.handleCommand}" width="800px"
welcomeMessage="Welcome to PrimeFaces Terminal, how are you today?"/>
</p:dialog>