Apply the last version by Shobhit and finally activate SSH

cusax-fix
Benoit Pradelle 18 years ago
parent ffd5c40f70
commit 2a144b5a1f

@ -1007,7 +1007,7 @@ javax.swing.event, javax.swing.border"/>
manifest="${src}/net/java/sip/communicator/impl/protocol/ssh/ssh.provider.manifest.mf">
<zipfileset dir="${dest}/net/java/sip/communicator/impl/protocol/ssh"
prefix="net/java/sip/communicator/impl/protocol/ssh"/>
<zipfileset src="${lib.noinst}/jsch-0.1.33.jar" prefix=""/>
<zipfileset src="${lib.noinst}/jsch-0.1.36.jar" prefix=""/>
<zipfileset dir="${resources}/images/protocol/ssh"
prefix="resources/images/protocol/ssh"/>
</jar>

@ -36,7 +36,10 @@ org.osgi.framework.system.packages= org.osgi.framework; ; version=1.3.0, \
org.jdesktop.jdic.tray; \
org.jdesktop.jdic.desktop; \
com.apple.eio; \
org.xml.sax.helpers;
org.xml.sax.helpers; \
javax.crypto; \
javax.crypto.spec; \
javax.crypto.interfaces;
felix.auto.start.10= reference:file:lib/bundle/org.apache.felix.bundlerepository-1.0.0.jar \
reference:file:lib/bundle/org.apache.felix.servicebinder-0.9.0-SNAPSHOT.jar
@ -72,6 +75,7 @@ felix.auto.start.50= \
reference:file:sc-bundles/protocol-msn.jar \
reference:file:sc-bundles/protocol-yahoo.jar \
reference:file:sc-bundles/protocol-gibberish.jar \
reference:file:sc-bundles/protocol-ssh.jar \
reference:file:sc-bundles/netaddr.jar \
reference:file:sc-bundles/protocol-rss.jar \
reference:file:sc-bundles/protocol-zeroconf.jar \
@ -100,6 +104,7 @@ felix.auto.start.60= \
reference:file:sc-bundles/msnaccregwizz.jar \
reference:file:sc-bundles/yahooaccregwizz.jar \
reference:file:sc-bundles/gibberishaccregwizz.jar \
reference:file:sc-bundles/sshaccregwizz.jar \
reference:file:sc-bundles/extendedcallhistorysearch.jar \
reference:file:sc-bundles/rssaccregwizz.jar \
reference:file:sc-bundles/zeroconfaccregwizz.jar \

@ -20,8 +20,8 @@
* the SSH protocol is not a real one, we simply store all group details
* in class fields. You should know that when implementing a real protocol,
* the contact group implementation would rather encapsulate group objects from
* the protocol stack and group property values should be returned by consulting
* the encapsulated object.
* the protocol stack and group property values should be returned by
* consulting the encapsulated object.
*
* @author Shobhit Jindal
*/
@ -162,7 +162,8 @@ public int countSubgroups()
/**
* Adds the specified contact group to the contained by this group.
* @param subgroup the ContactGroupSSHImpl to add as a subgroup to this group.
* @param subgroup the ContactGroupSSHImpl to add as a subgroup to this
* group.
*/
public void addSubgroup(ContactGroupSSHImpl subgroup)
{
@ -432,15 +433,16 @@ public String toString()
}
/**
* Specifies whether or not this contact group is being stored by the server.
* Specifies whether or not this contact group is being stored by the
* server.
* Non persistent contact groups are common in the case of simple,
* non-persistent presence operation sets. They could however also be seen
* in persistent presence operation sets when for example we have received
* an event from someone not on our contact list and the contact that we
* associated with that user is placed in a non persistent group. Non
* persistent contact groups are volatile even when coming from a persistent
* presence op. set. They would only exist until the application is closed
* and will not be there next time it is loaded.
* persistent contact groups are volatile even when coming from a
* persistent presence op. set. They would only exist until the
* application is closed and will not be there next time it is loaded.
*
* @param isPersistent true if the contact group is to be persistent and
* false otherwise.

@ -200,11 +200,11 @@ void initializeShellIO (InputStream shellInputStream,
public void savePersistentDetails ();
/*
* Returns the OperationSetContactInfo associated with this contact
* Returns the SSHContactInfo associated with this contact
*
* @return sshConfigurationForm
*/
public OperationSetContactInfo getSSHConfigurationForm ();
public SSHContactInfo getSSHConfigurationForm ();
/**
* Returns the JSch Stack identified associated with this contact

@ -45,7 +45,7 @@ public class ContactSSHImpl
/**
* Interface for user to provide details about machine
*/
private OperationSetContactInfo sshConfigurationForm;
private SSHContactInfo sshConfigurationForm;
/**
* A Timer Daemon to update the status of this contact
@ -55,7 +55,7 @@ public class ContactSSHImpl
/**
* A Daemon to retrieve and fire messages received from remote machine
*/
private ContactSSHReaderDaemon contactSSHReaderDaemon;
private SSHReaderDaemon contactSSHReaderDaemon;
/**
* The id of the contact.
@ -175,7 +175,7 @@ public ContactSSHImpl(
this.parentProvider = parentProvider;
this.sshConfigurationForm =
new OperationSetContactInfo(this);
new SSHContactInfo(this);
this.savePersistentDetails();
}
@ -195,7 +195,7 @@ public void initializeShellIO(
shellReader = new InputStreamReader(shellInputStream);
shellWriter = new PrintWriter(shellOutputStream);
contactSSHReaderDaemon = new ContactSSHReaderDaemon(this);
contactSSHReaderDaemon = new SSHReaderDaemon(this);
contactSSHReaderDaemon.setDaemon(true);
contactSSHReaderDaemon.isActive(true);
contactSSHReaderDaemon.start();
@ -249,7 +249,8 @@ public void closeShellIO()
jsch = null;
}
((OperationSetPersistentPresenceSSHImpl)getParentPresenceOperationSet()).
((OperationSetPersistentPresenceSSHImpl)
getParentPresenceOperationSet()).
changeContactPresenceStatus(this, SSHStatusEnum.ONLINE);
}
@ -277,7 +278,8 @@ public void sendLine(String message)
// String line = shellReader.readLine();
//// logger.debug("SSH FROM: " + this.contactID + ": " + line);
//
// // null is never returned normally, the reading attempt returs a string
// // null is never returned normally, the reading attempt returs a
// // string
// // or blocks until one line is available
// if(line == null)
// {
@ -295,7 +297,7 @@ public void sendLine(String message)
*/
public void startTimerTask()
{
timer.scheduleAtFixedRate(new OperationSetContactTimerSSHImpl(this),
timer.scheduleAtFixedRate(new ContactTimerSSHImpl(this),
2000, sshConfigurationForm.getUpdateInterval()*1000);
}
@ -310,7 +312,8 @@ public void stopTimerTask()
/**
* Saves the details of contact in persistentData seperated by detailsSeperator
* Saves the details of contact in persistentData seperated by
* detailsSeperator
* Passowrd is saved unsecurely using Base64 encoding
*/
public void savePersistentDetails()
@ -396,17 +399,18 @@ public boolean isConnectionInProgress()
*
* @param isConnectionInProgress
*/
public synchronized void setConnectionInProgress(boolean isConnectionInProgress)
public synchronized void setConnectionInProgress(
boolean isConnectionInProgress)
{
this.isConnectionInProgress = isConnectionInProgress;
}
/**
* Returns the OperationSetContactInfo associated with this contact
*
* Returns the SSHContactInfo associated with this contact
*
* @return sshConfigurationForm
*/
public OperationSetContactInfo getSSHConfigurationForm()
public SSHContactInfo getSSHConfigurationForm()
{
return this.sshConfigurationForm;
}
@ -704,8 +708,8 @@ public boolean equals(Object obj)
}
/**
* Returns the BasicInstant Messaging operation set that this contact belongs
* to.
* Returns the BasicInstant Messaging operation set that this contact
* belongs to.
*
* @return the <tt>OperationSetBasicInstantMessagingSSHImpl</tt> that
* this contact belongs to.
@ -785,7 +789,8 @@ public InputStream getShellInputStream()
// /**
// * Sets the Input Stream associated with SSH Channel of this contact
// *
// * @param shellInputStream to be associated with SSH Channel of this contact
// * @param shellInputStream to be associated with SSH Channel of
// * this contact
// */
// public void setShellInputStream(InputStream shellInputStream)
// {
@ -882,16 +887,6 @@ public void setPassword(String password)
this.sshConfigurationForm.setPasswordField(password);
savePersistentDetails();
}
/**
* Return the current status message of this contact.
*
* @return null as the protocol has no support of status messages
*/
public String getStatusMessage()
{
return null;
}
// /**
// * Sets the PS1 prompt of the current shell of Contact
@ -912,4 +907,13 @@ public String getStatusMessage()
// {
// return this.sshPrompt;
// }
/**
* Return the current status message of this contact.
*
* @return the current status message
*/
public String getStatusMessage() {
return presenceStatus.getStatusName();
}
}

@ -4,19 +4,21 @@
* Distributable under LGPL license.
* See terms of license at gnu.org.
*
* OperationSetContactTimerSSHImpl.java
* ContactTimerSSHImpl.java
*
* SSH Suport in SIP Communicator - GSoC' 07 Project
*/
package net.java.sip.communicator.impl.protocol.ssh;
import java.io.IOException;
import java.net.*;
import java.util.*;
import net.java.sip.communicator.util.*;
/**
* Timer Task to update the reachability status of SSH Contact in contact list
* Timer Task to update the reachability status of SSH Contact in contact list.
* (Reachability of remote machine from user's machine)
* The timer is started at either of the two places
* - A new contact - OperationSetPersistentPresenceSSHImpl
* .createUnresolvedContact
@ -24,7 +26,7 @@
*
* @author Shobhit Jindal
*/
public class OperationSetContactTimerSSHImpl
public class ContactTimerSSHImpl
extends TimerTask
{
private static final Logger logger
@ -50,62 +52,47 @@ public void run()
{
try
{
/* InetAddress remoteMachine = InetAddress.getByName(
InetAddress remoteMachine = InetAddress.getByName(
sshContact.getSSHConfigurationForm().getHostName());
//check if machine is reachable
if(remoteMachine.isReachable(
sshContact.getSSHConfigurationForm().getUpdateInterval()))
{
if(
! sshContact.getPresenceStatus().equals(SSHStatusEnum
.ONLINE)
&&
! sshContact.getPresenceStatus().equals(SSHStatusEnum
.CONNECTING)
&&
! sshContact.getPresenceStatus().equals(SSHStatusEnum
.CONNECTED)
)
*/
Socket socket = new Socket(
sshContact.getSSHConfigurationForm().getHostName(),
sshContact.getSSHConfigurationForm().getPort());
socket.close();
if (sshContact.getPresenceStatus().equals(SSHStatusEnum.OFFLINE)
if (sshContact.getPresenceStatus().equals(SSHStatusEnum.OFFLINE)
|| sshContact.getPresenceStatus().equals(SSHStatusEnum
.NOT_AVAILABLE))
{
// change status to online
persistentPresence.changeContactPresenceStatus(
sshContact, SSHStatusEnum.ONLINE);
logger.debug("SSH Host " + sshContact.getSSHConfigurationForm()
.getHostName() + ": Online");
.NOT_AVAILABLE))
{
// change status to online
persistentPresence.changeContactPresenceStatus(
sshContact, SSHStatusEnum.ONLINE);
logger.debug("SSH Host " + sshContact
.getSSHConfigurationForm().getHostName() + ": Online");
}
}
else throw new IOException();
}
catch (Exception ex)
catch (IOException ex)
{
if (sshContact.getPresenceStatus().equals(SSHStatusEnum.ONLINE)
|| sshContact.getPresenceStatus().equals(SSHStatusEnum
.NOT_AVAILABLE))
|| sshContact.getPresenceStatus().equals(
SSHStatusEnum.NOT_AVAILABLE))
{
persistentPresence.changeContactPresenceStatus(
sshContact, SSHStatusEnum.OFFLINE);
logger.debug("SSH Host " + sshContact.getSSHConfigurationForm()
.getHostName() + ": Offline");
.getHostName() + ": Offline");
}
}
}
/**
* Creates a new instance of OperationSetContactTimerSSHImpl
* Creates a new instance of ContactTimerSSHImpl
*/
public OperationSetContactTimerSSHImpl(ContactSSH sshContact)
public ContactTimerSSHImpl(ContactSSH sshContact)
{
super();
this.sshContact = sshContact;

@ -28,9 +28,9 @@ public class MessageSSHImpl
private String textContent = null;
/**
* The content type of the message. (text/plain if null)
* The content type of the message.
*/
private String contentType = null;
public static String contentType = "text/plain";
/**
* The message encoding. (UTF8 if null).

@ -50,32 +50,19 @@ public class OperationSetBasicInstantMessagingSSHImpl
*/
private ProtocolProviderServiceSSHImpl parentProvider = null;
/**
* The test command given after each command to determine the reply length
* of the command
*/
private final String testCommand = Resources.getString("testCommand");
private String testCommandResponse = Resources
.getString("testCommandResponse");
/**
* Creates an instance of this operation set keeping a reference to the
* parent protocol provider and presence operation set.
*
* @param provider The provider instance that creates us.
* @param opSetPersPresence the currently valid
* <tt>OperationSetPersistentPresenceSSHImpl</tt> instance.
*/
public OperationSetBasicInstantMessagingSSHImpl(
ProtocolProviderServiceSSHImpl provider,
OperationSetPersistentPresenceSSHImpl opSetPersPresence)
// OperationSetFileTransferSSHImpl fileTransfer)
ProtocolProviderServiceSSHImpl provider)
{
this.opSetPersPresence = opSetPersPresence;
this.parentProvider = provider;
// this.fileTransfer = fileTransfer;
this.opSetPersPresence = (OperationSetPersistentPresenceSSHImpl)
provider.getOperationSet(OperationSetPersistentPresence.class);
}
/**
@ -237,8 +224,9 @@ private boolean wrappedMessage(
sshContact,
null,
message.substring(message.indexOf(' ', firstSpace+1) + 1),
message.substring(firstSpace+1, message.indexOf(' ', firstSpace+1))
);
message.substring(
firstSpace+1,
message.indexOf(' ', firstSpace+1)));
return true;
}
@ -248,7 +236,8 @@ else if(message.startsWith("/download"))
sshContact.getFileTransferOperationSet().sendFile(
null,
sshContact,
message.substring(firstSpace+1, message.indexOf(' ', firstSpace+1)),
message.substring(firstSpace+1, message.indexOf(' ',
firstSpace+1)),
message.substring(message.indexOf(' ', firstSpace+1) + 1));
return true;
@ -398,7 +387,7 @@ public boolean isOfflineMessagingSupported()
*/
public boolean isContentTypeSupported(String contentType)
{
return false;
return MessageSSHImpl.contentType.equals(contentType);
}
}

@ -52,13 +52,13 @@ public class OperationSetFileTransferSSHImpl
/** Creates a new instance of OperationSetFileTransferSSHImpl */
public OperationSetFileTransferSSHImpl(
ProtocolProviderServiceSSHImpl parentProvider,
OperationSetPersistentPresenceSSHImpl opSetPersPresence,
OperationSetBasicInstantMessagingSSHImpl instantMessaging)
ProtocolProviderServiceSSHImpl parentProvider)
{
this.parentProvider = parentProvider;
this.opSetPersPresence = opSetPersPresence;
this.instantMessaging = instantMessaging;
this.opSetPersPresence = (OperationSetPersistentPresenceSSHImpl)
parentProvider.getOperationSet(OperationSetPersistentPresence.class);
this.instantMessaging = (OperationSetBasicInstantMessagingSSHImpl)
parentProvider.getOperationSet(OperationSetBasicInstantMessaging.class);
}
/**
@ -91,16 +91,14 @@ public void sendFile(
{
if(toContact == null)
{
ContactSSHFileTransferDaemon fileTransferDaemon
= new ContactSSHFileTransferDaemon(
SSHFileTransferDaemon fileTransferDaemon
= new SSHFileTransferDaemon(
(ContactSSH)fromContact,
opSetPersPresence,
instantMessaging,
parentProvider);
if(localPath.endsWith(System.getProperty("file.separator")))
localPath += remotePath.substring(remotePath.lastIndexOf('/')
+ 1);
localPath += remotePath.substring(remotePath.lastIndexOf(
System.getProperty("file.separator")) + 1);
fileTransferDaemon.downloadFile(
remotePath,
@ -110,11 +108,9 @@ public void sendFile(
}
else if(fromContact == null)
{
ContactSSHFileTransferDaemon fileTransferDaemon
= new ContactSSHFileTransferDaemon(
SSHFileTransferDaemon fileTransferDaemon
= new SSHFileTransferDaemon(
(ContactSSH) toContact,
opSetPersPresence,
instantMessaging,
parentProvider);
fileTransferDaemon.uploadFile(
@ -125,7 +121,7 @@ else if(fromContact == null)
}
// code should not reach here
//assert false;
// assert false;
logger.error("we should not be here !");
}

@ -68,7 +68,7 @@ public class OperationSetPersistentPresenceSSHImpl
/**
* The currently active status message.
*/
private String statusMessage = "Default Status Message";
private String statusMessage = "Online";
/**
* Our default presence status.
@ -1044,7 +1044,7 @@ public Contact createUnresolvedContact(
String osgiQuery = "(&"
+ "(" + ProtocolProviderFactory.PROTOCOL
+ "=SSH)"
+ "=" + ProtocolNames.SSH + ")"
+ "(" + ProtocolProviderFactory.USER_ID
+ "=" + sshUserID + ")"
+ ")";

@ -180,7 +180,7 @@ public AccountID loadAccount(Map accountProperties)
//properties we have in it.
Hashtable properties = new Hashtable();
properties.put(PROTOCOL, "SSH");
properties.put(PROTOCOL, ProtocolNames.SSH);
properties.put(USER_ID, userIDStr);
ProtocolProviderServiceSSHImpl sshProtocolProvider

@ -38,7 +38,7 @@ public class ProtocolProviderServiceSSHImpl
/**
* The name of this protocol.
*/
public static final String SSH_PROTOCOL_NAME = "SSH";
public static final String SSH_PROTOCOL_NAME = ProtocolNames.SSH;
// /**
// * The identifier for SSH Stack
@ -167,8 +167,7 @@ protected void initialize(
//initialize the IM operation set
basicInstantMessaging = new
OperationSetBasicInstantMessagingSSHImpl(
this,
persistentPresence);
this);
supportedOperationSets.put(
OperationSetBasicInstantMessaging.class.getName(),
@ -176,9 +175,7 @@ protected void initialize(
//initialze the file transfer operation set
fileTranfer = new OperationSetFileTransferSSHImpl(
this,
persistentPresence,
basicInstantMessaging);
this);
supportedOperationSets.put(
OperationSetFileTransfer.class.getName(),
@ -242,7 +239,7 @@ public boolean isShellConnected(ContactSSH sshContact)
* a new jsch session is also created if the current one is invalid
*
* @param sshContact the contact of the remote machine
* @param Message the first message
* @param firstMessage the first message
*/
public void connectShell(
final ContactSSH sshContact,
@ -370,7 +367,8 @@ public void closeShellChannel(ContactSSH sshContact) throws
*
* @param sshContact ID of SSH Contact
*
* @throws JSchException if a JSch is unable to create a SSH Session with the remote machine
* @throws JSchException if a JSch is unable to create a SSH Session with
* the remote machine
* @throws InterruptedException if the thread is interrupted before session
* connected or is timed out
* @throws OperationFailedException if not of above reasons :-)

@ -60,14 +60,19 @@ public static String getString(String key)
*/
public static byte[] getImage(ImageID imageID)
{
byte[] image = new byte[100000];
byte[] image= null;
InputStream inputStream;
String path = Resources.getString(imageID.getId());
try
{
Resources.class.getClassLoader()
.getResourceAsStream(path).read(image);
inputStream = Resources.class.getClassLoader()
.getResourceAsStream(path);
image = new byte[inputStream.available()];
inputStream.read(image);
}
catch (IOException exc)
{

@ -4,7 +4,7 @@
* Distributable under LGPL license.
* See terms of license at gnu.org.
*
* OperationSetContactInfo.java
* SSHContactInfo.java
*
* SSH Suport in SIP Communicator - GSoC' 07 Project
*
@ -12,19 +12,20 @@
package net.java.sip.communicator.impl.protocol.ssh;
import java.text.ParseException;
import net.java.sip.communicator.service.gui.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
/**
*
* @author Shobhit Jindal
*/
class OperationSetContactInfo extends JDialog
implements ConfigurationForm
{
class SSHContactInfo extends JDialog
implements ConfigurationForm {
private ContactSSH sshContact;
private JPanel mainPanel = new JPanel();
@ -43,7 +44,8 @@ class OperationSetContactInfo extends JDialog
private JLabel password = new JLabel("Password: ");
private JTextField passwordField = new JPasswordField();
private JLabel port = new JLabel("Port: ");
private JTextField portField = new JTextField("22");
private JFormattedTextField portField;
private JLabel secs = new JLabel("secs");
private JLabel statusUpdate = new JLabel("Update Interval: ");
private JLabel terminalType = new JLabel("Terminal Type: ");
@ -75,12 +77,11 @@ class OperationSetContactInfo extends JDialog
// private ContactGroup contactGroup = null;
/**
* Creates a new instance of OperationSetContactInfo
* Creates a new instance of SSHContactInfo
*
* @param sshContact the concerned contact
*/
public OperationSetContactInfo(ContactSSH sshContact)
{
public SSHContactInfo(ContactSSH sshContact) {
super(new JFrame(), true);
this.sshContact = sshContact;
initForm();
@ -108,9 +109,17 @@ public OperationSetContactInfo(ContactSSH sshContact)
/**
* initialize the form.
*/
public void initForm()
{
public void initForm() {
updateTimer.setValue(new Integer(30));
MaskFormatter maskFormatter = new MaskFormatter();
try {
maskFormatter.setMask("#####");
} catch (ParseException ex) {
ex.printStackTrace();
}
maskFormatter.setAllowsInvalid(false);
portField = new JFormattedTextField(maskFormatter);
portField.setValue(new Integer(22));
userNameField.setEnabled(false);
passwordField.setEditable(false);
@ -120,9 +129,9 @@ public void initForm()
mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
machinePanel.setLayout(new BoxLayout(machinePanel, BoxLayout.X_AXIS));
detailNamesPanel.setLayout(new BoxLayout(detailNamesPanel,
detailNamesPanel.setLayout(new BoxLayout(detailNamesPanel,
BoxLayout.Y_AXIS));
detailFieldsPanel.setLayout(new BoxLayout(detailFieldsPanel,
detailFieldsPanel.setLayout(new BoxLayout(detailFieldsPanel,
BoxLayout.Y_AXIS));
detailsPanel.setLayout(new BoxLayout(detailsPanel, BoxLayout.X_AXIS));
@ -162,10 +171,8 @@ public void initForm()
mainPanel.add(doneButton);
mainPanel.add(emptyPanel11);
addDetailsCheckBox.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
addDetailsCheckBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
addDetailsCheckBox.setEnabled(false);
userNameField.setEnabled(true);
passwordField.setEditable(true);
@ -177,12 +184,9 @@ public void actionPerformed(ActionEvent event)
}
});
doneButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
if(machineIDField.getText().equals(""))
{
doneButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
if(machineIDField.getText().equals("")) {
machineIDField.setText("Field needed");
return;
}
@ -192,27 +196,25 @@ public void actionPerformed(ActionEvent event)
// .getParentPresenceOperationSet())
// .addContactToList(contactGroup, sshContact);
setVisible(false);
}
}
});
}
/**
* Return the ssh icon
*
*
* @return the ssh icon
*/
public byte[] getIcon()
{
public byte[] getIcon() {
return Resources.getImage(Resources.SSH_LOGO);
}
/**
* Return the main panel
*
*
* @return the main panel
*/
public Object getForm()
{
public Object getForm() {
return mainPanel;
}
//
@ -231,8 +233,7 @@ public Object getForm()
*
* @param userName to be associated
*/
public void setUserNameField(String userName)
{
public void setUserNameField(String userName) {
this.userNameField.setText(userName);
}
@ -241,68 +242,61 @@ public void setUserNameField(String userName)
*
* @param password to be associated
*/
public void setPasswordField(String password)
{
public void setPasswordField(String password) {
this.passwordField.setText(password);
}
/**
* Return the hostname
*
*
* @return the hostname
*/
public String getHostName()
{
public String getHostName() {
return this.machineIDField.getText();
}
/**
* Return the username
*
*
* @return the username
*/
public String getUserName()
{
public String getUserName() {
return this.userNameField.getText();
}
/**
* Return the password
*
*
* @return the password in a clear form
*/
public String getPassword()
{
public String getPassword() {
return this.passwordField.getText();
}
/**
* Return the terminal type
*
*
* @return the terminal type
*/
public String getTerminalType()
{
public String getTerminalType() {
return this.terminalTypeField.getText();
}
/**
* Return the port
*
*
* @return the port value
*/
public int getPort()
{
return Integer.parseInt(this.portField.getText());
public int getPort() {
return Integer.parseInt(this.portField.getText().trim());
}
/**
* Return the update interval
*
*
* @return the update interval
*/
public int getUpdateInterval()
{
public int getUpdateInterval() {
return Integer.parseInt(String.valueOf(this.updateTimer.getValue()));
}
@ -311,8 +305,7 @@ public int getUpdateInterval()
*
* @param hostName to be associated
*/
public void setHostNameField(String hostName)
{
public void setHostNameField(String hostName) {
this.machineIDField.setText(hostName);
}
@ -321,8 +314,7 @@ public void setHostNameField(String hostName)
*
* @param termType to be associated
*/
public void setTerminalType(String termType)
{
public void setTerminalType(String termType) {
this.terminalTypeField.setText(termType);
}
@ -331,8 +323,7 @@ public void setTerminalType(String termType)
*
* @param interval to be associated
*/
public void setUpdateInterval(Integer interval)
{
public void setUpdateInterval(Integer interval) {
this.updateTimer.setValue(interval);
}
@ -341,8 +332,7 @@ public void setUpdateInterval(Integer interval)
*
* @param port to be associated
*/
public void setPort(String port)
{
public void setPort(String port) {
this.portField.setText(port);
}
}

@ -4,7 +4,7 @@
* Distributable under LGPL license.
* See terms of license at gnu.org.
*
* ContactSSHFileTransferDaemon.java
* SSHFileTransferDaemon.java
*
* SSH Suport in SIP Communicator - GSoC' 07 Project
*
@ -23,11 +23,11 @@
*
* @author Shobhit Jindal
*/
public class ContactSSHFileTransferDaemon
public class SSHFileTransferDaemon
extends Thread
{
private static final Logger logger =
Logger.getLogger(ContactSSHFileTransferDaemon .class);
Logger.getLogger(SSHFileTransferDaemon .class);
/**
* The contact of the remote machine
@ -96,23 +96,23 @@ public class ContactSSHFileTransferDaemon
private OperationSetBasicInstantMessagingSSHImpl instantMessaging = null;
/**
* Creates a new instance of ContactSSHFileTransferDaemon
* Creates a new instance of SSHFileTransferDaemon
*
*
* @param sshContact The contact of the remote machine
* @param opSetPersPresence The current ssh presence operation set
* @param instantMessaging The current ssh instant messaging operation set
* @param ppService The current ssh protocol provider
*/
public ContactSSHFileTransferDaemon(
public SSHFileTransferDaemon(
ContactSSH sshContact,
OperationSetPersistentPresenceSSHImpl opSetPersPresence,
OperationSetBasicInstantMessagingSSHImpl instantMessaging,
ProtocolProviderServiceSSHImpl ppService)
{
super();
this.sshContact = sshContact;
this.opSetPersPresence = opSetPersPresence;
this.instantMessaging = instantMessaging;
this.opSetPersPresence = (OperationSetPersistentPresenceSSHImpl)
ppService.getOperationSet(OperationSetPersistentPresence.class);
this.instantMessaging = (OperationSetBasicInstantMessagingSSHImpl)
ppService.getOperationSet(
OperationSetBasicInstantMessaging.class);
this.ppService = ppService;
}
@ -225,7 +225,6 @@ public void run()
instantMessaging.createMessage(ex.getMessage()),
sshContact);
ex.printStackTrace();
logger.error(ex.getMessage());
try
@ -405,7 +404,7 @@ private void download()
}
String file=null;
for(int i=0;;i++)
for(int i=0;true;i++)
{
scpInputStream.read(buffer, i, 1);
if(buffer[i]==(byte)0x0a)
@ -433,10 +432,8 @@ private void download()
foo = scpInputStream.read(buffer, 0, foo);
if(foo<0)
{
// error
break;
}
fileOutputStream.write(buffer, 0, foo);
filesize-=foo;
if(filesize==0L) break;

@ -4,7 +4,7 @@
* Distributable under LGPL license.
* See terms of license at gnu.org.
*
* ContactSSHReaderDaemon.java
* SSHReaderDaemon.java
*
* SSH Suport in SIP Communicator - GSoC' 07 Project
*
@ -22,11 +22,11 @@
*
* @author Shobhit Jindal
*/
public class ContactSSHReaderDaemon
public class SSHReaderDaemon
extends Thread
{
private static final Logger logger =
Logger.getLogger(ContactSSHReaderDaemon.class);
Logger.getLogger(SSHReaderDaemon.class);
/**
* A Buffer to aggregate replies to be sent as one message
@ -75,12 +75,14 @@ public class ContactSSHReaderDaemon
private int bytesRead;
char buffer[] = new char[1024], buf;
int bufferCount;
char buf;
/**
* Creates a new instance of ContactSSHReaderDaemon
* Creates a new instance of SSHReaderDaemon
*/
public ContactSSHReaderDaemon(ContactSSH sshContact)
public SSHReaderDaemon(ContactSSH sshContact)
{
this.sshContact = (ContactSSHImpl)sshContact;
instantMessaging = (OperationSetBasicInstantMessagingSSHImpl) sshContact
@ -97,7 +99,8 @@ public void run()
shellInputStream = sshContact.getShellInputStream();
shellReader = sshContact.getShellReader();
replyBuffer = new StringBuffer();
try
{
do
@ -109,11 +112,14 @@ public void run()
// wait if more data is available
// for a slower connection this value need to be raised
// to avoid splitting of messages
Thread.sleep(50);
Thread.sleep(250);
continue;
}
bufferCount = 0;
// if(replyBuffer > 0)
do
{
// store the responses in a buffer
@ -123,7 +129,7 @@ public void run()
bytesAvailable = shellInputStream.available();
}while(bytesAvailable > 0 );
}while(bytesAvailable > 0 && bufferCount<16384);
message = replyBuffer.toString();
@ -186,9 +192,11 @@ private void storeMessage(StringBuffer replyBuffer) throws IOException
// logger.debug(shellReader.readLine());
bufferCount++;
bytesAvailable--;
}while(bytesAvailable>0);
}while(bytesAvailable>0 && bufferCount<32700);
}
public void isActive(boolean isActive)

@ -40,8 +40,8 @@ public class SSHStatusEnum
/**
* The Not Available status. Indicates that the user has connectivity
* but might not be able to immediately act (i.e. even less immediately than
* when in an Away status ;-P ) upon initiation of communication.
* but might not be able to immediately act (i.e. even less immediately
* than when in an Away status ;-P ) upon initiation of communication.
*
*/
public static final SSHStatusEnum NOT_AVAILABLE
@ -68,7 +68,7 @@ public class SSHStatusEnum
= new SSHStatusEnum(
65
, "Online"
, loadIcon("resources/images/ssh/ssh-online.png"));
, loadIcon("resources/images/protocol/ssh/ssh-online.png"));
/**
@ -79,7 +79,7 @@ public class SSHStatusEnum
= new SSHStatusEnum(
70
, "Connecting"
, loadIcon("resources/images/ssh/ssh-connected.png"));
, loadIcon("resources/images/protocol/ssh/ssh-connected.png"));
/**
* The File Transfer status. Indicate that the user is transfering a file
@ -89,7 +89,7 @@ public class SSHStatusEnum
= new SSHStatusEnum(
75
, "Transfering File"
, loadIcon("resources/images/ssh/ssh-filetransfer.png"));
, loadIcon("resources/images/protocol/ssh/ssh-filetransfer.png"));
/**
* Initialize the list of supported status states.
@ -131,7 +131,7 @@ static Iterator supportedStatusSet()
/**
* Loads an image from a given image path.
* @param imagePath The path to the image resource.
* @return The image extracted from the resource at the specified path.
* @return The image extracted from the resource at the specified path.
*/
public static byte[] loadIcon(String imagePath)
{

@ -74,7 +74,7 @@ public boolean promptYesNo(String str)
str,
"Warning",
JOptionPane.DEFAULT_OPTION,
JOptionPane.WARNING_MESSAGE,
JOptionPane.QUESTION_MESSAGE,
null, options, options[0]);
return foo==0;
}

@ -1,13 +1,4 @@
#The test command should be choosen uniquely i.e. it should not appear in output
# of any other command(including its own), else the reply of the offending
# command will be cut short
testCommand=uname
#First line of reply of test command (must be independent of state of remote
# machine)
testCommandResponse=Linux
#Contact Details Seperator(must not be part of contact data stored as persistent
# data)
detailsSeperator=~
#Connection timeout to a remote server in seconds
connectionTimeout=30
protocolIcon=resources/images/ssh/ssh-online.png
protocolIcon=resources/images/protocol/ssh/ssh-online.png

@ -6,6 +6,7 @@ Bundle-Version: 0.0.1
Import-Package: org.osgi.framework,
javax.swing,
javax.swing.border,
javax.swing.text,
javax.crypto,
javax.crypto.spec,
javax.crypto.interfaces,

@ -97,45 +97,56 @@ public class FirstWizardPage
private Object nextPageIdentifier = WizardPage.SUMMARY_PAGE_IDENTIFIER;
private SSHAccountRegistrationWizard wizard;
private SSHAccountRegistration registration = null;
private WizardContainer wizardContainer;
/**
* Creates an instance of <tt>FirstWizardPage</tt>.
* @param wizard the parent wizard
* @param registration the <tt>SSHAccountRegistration</tt>, where
* all data through the wizard are stored
* @param wizardContainer the wizardContainer, where this page will
* be added
*/
public FirstWizardPage(SSHAccountRegistrationWizard wizard)
public FirstWizardPage(SSHAccountRegistration registration,
WizardContainer wizardContainer)
{
super(new BorderLayout());
this.wizard = wizard;
this.wizardContainer = wizardContainer;
this.registration = registration;
this.setPreferredSize(new Dimension(300, 150));
mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
identityFileField.setEditable(false);
knownHostsFileField.setEditable(false);
identityFileChooser.setFileHidingEnabled(false);
knownHostsFileChooser.setFileHidingEnabled(false);
this.init();
this.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
this.labelsPanel.setLayout(new BoxLayout(labelsPanel,
BoxLayout.Y_AXIS));
this.valuesPanel.setLayout(new BoxLayout(valuesPanel,
BoxLayout.Y_AXIS));
this.identityFilePanel.setLayout(new BoxLayout(identityFilePanel,
BoxLayout.X_AXIS));
this.knownHostsFilePanel.setLayout(new BoxLayout(knownHostsFilePanel,
BoxLayout.X_AXIS));
}
/**
* Initializes all panels, buttons, etc.
*/
@ -202,7 +213,7 @@ public void actionPerformed(ActionEvent event)
public void actionPerformed(ActionEvent event)
{
int returnVal = knownHostsFileChooser.showDialog
(FirstWizardPage.this, "Select Identify File");
(FirstWizardPage.this, "Select SSH Known Hosts File");
if(returnVal == JFileChooser.APPROVE_OPTION)
knownHostsFileField.setText(knownHostsFileChooser
@ -238,7 +249,6 @@ public void loadAccount(ProtocolProviderService protocolProvider)
String knownHostsFile = (String) accountID.getAccountProperties()
.get(ProtocolProviderFactorySSH.KNOWN_HOSTS_FILE);
this.accountIDField.setEnabled(false);
this.accountIDField.setText(accountID.getUserID());
this.identityFileField.setText(identityFile);
@ -305,8 +315,8 @@ public void pageShowing()
public void pageNext()
{
String userID = accountIDField.getText();
if (!wizard.isModification() && isExistingAccount(userID))
if (isExistingAccount(userID))
{
nextPageIdentifier = FIRST_PAGE_IDENTIFIER;
accountPanel.add(existingAccountLabel, BorderLayout.NORTH);
@ -316,32 +326,30 @@ public void pageNext()
{
nextPageIdentifier = SUMMARY_PAGE_IDENTIFIER;
accountPanel.remove(existingAccountLabel);
SSHAccountRegistration registration = wizard.getRegistration();
registration.setAccountID(accountIDField.getText());
registration.setIdentityFile(identityFileField.getText());
registration.setKnownHostsFile(knownHostsFileField.getText());
}
}
/**
* Enables or disables the "Next" wizard button according to whether the
* User ID field is empty.
*/
private void setNextButtonAccordingToUserID()
{
if (accountIDField.getText() == null
|| accountIDField.getText().equals(""))
if (accountIDField.getText() == null || accountIDField.getText()
.equals(""))
{
wizard.getWizardContainer().setNextFinishButtonEnabled(false);
wizardContainer.setNextFinishButtonEnabled(false);
}
else
{
wizard.getWizardContainer().setNextFinishButtonEnabled(true);
wizardContainer.setNextFinishButtonEnabled(true);
}
}
/**
* Handles the <tt>DocumentEvent</tt> triggered when user types in the
* User ID field. Enables or disables the "Next" wizard button according to

@ -65,20 +65,25 @@ public static String getString(String key)
*/
public static byte[] getImage(ImageID imageID)
{
byte[] image = new byte[100000];
byte[] image=null;
InputStream inputStream;
String path = Resources.getString(imageID.getId());
try
{
Resources.class.getClassLoader()
.getResourceAsStream(path).read(image);
inputStream = Resources.class.getClassLoader()
.getResourceAsStream(path);
image = new byte[inputStream.available()];
inputStream.read(image);
}
catch (IOException exc)
{
log.error("Failed to load image:" + path, exc);
}
return image;
}

@ -40,13 +40,11 @@ public class SSHAccRegWizzActivator
* A currently valid reference to the configuration service.
*/
private static ConfigurationService configService;
private static AccountRegistrationWizardContainer wizardContainer;
private static SSHAccountRegistrationWizard sshWizard;
private static UIService uiService;
/**
* Starts this bundle.
* @param bc the currently valid <tt>BundleContext</tt>.
@ -60,7 +58,8 @@ public void start(BundleContext bc)
ServiceReference uiServiceRef = bundleContext
.getServiceReference(UIService.class.getName());
uiService = (UIService) bundleContext.getService(uiServiceRef);
UIService uiService = (UIService) bundleContext
.getService(uiServiceRef);
wizardContainer = uiService.getAccountRegWizardContainer();
@ -118,14 +117,4 @@ public BundleContext getBundleContext()
{
return bundleContext;
}
/**
* Returns the <tt>UIService</tt>.
*
* @return the <tt>UIService</tt>
*/
public static UIService getUIService()
{
return uiService;
}
}

@ -23,7 +23,16 @@
public class SSHAccountRegistration
{
private String accountID;
/**
* Stored public keys[SSH] of remote server
*/
private String knownHostsFile;
/**
* Identity file is a private[default] key of the user which is one
* of the methods of authentication
*/
private String identityFile;
/**

@ -18,6 +18,7 @@
import java.util.*;
import org.osgi.framework.*;
import net.java.sip.communicator.impl.gui.customcontrols.*;
import net.java.sip.communicator.service.gui.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.impl.protocol.ssh.*;
@ -30,58 +31,55 @@
* @author Shobhit Jindal
*/
public class SSHAccountRegistrationWizard
implements AccountRegistrationWizard
{
implements AccountRegistrationWizard {
/**
* The first page of the ssh account registration wizard.
*/
private FirstWizardPage firstWizardPage;
/**
* The object that we use to store details on an account that we will be
* creating.
*/
private SSHAccountRegistration registration
= new SSHAccountRegistration();
= new SSHAccountRegistration();
private WizardContainer wizardContainer;
private ProtocolProviderService protocolProvider;
private String propertiesPackage
= "net.java.sip.communicator.plugin.sshaccregwizz";
= "net.java.sip.communicator.plugin.sshaccregwizz";
private boolean isModification;
/**
* Creates an instance of <tt>SSHAccountRegistrationWizard</tt>.
* @param wizardContainer the wizard container, where this wizard
* is added
*/
public SSHAccountRegistrationWizard(WizardContainer wizardContainer)
{
public SSHAccountRegistrationWizard(WizardContainer wizardContainer) {
this.wizardContainer = wizardContainer;
}
/**
* Implements the <code>AccountRegistrationWizard.getIcon</code> method.
* Returns the icon to be used for this wizard.
* @return byte[]
*/
public byte[] getIcon()
{
public byte[] getIcon() {
return Resources.getImage(Resources.SSH_LOGO);
}
/**
* Implements the <code>AccountRegistrationWizard.getPageImage</code>
* method.
* Returns the image used to decorate the wizard page
*
*
* @return byte[] the image used to decorate the wizard page
*/
public byte[] getPageImage()
{
public byte[] getPageImage() {
return Resources.getImage(Resources.PAGE_IMAGE);
}
@ -90,208 +88,142 @@ public byte[] getPageImage()
* method. Returns the protocol name for this wizard.
* @return String
*/
public String getProtocolName()
{
public String getProtocolName() {
return Resources.getString("protocolName");
}
/**
* Implements the <code>AccountRegistrationWizard.getProtocolDescription
* </code> method. Returns the description of the protocol for this wizard.
* @return String
*/
public String getProtocolDescription()
{
public String getProtocolDescription() {
return Resources.getString("protocolDescription");
}
/**
* Returns the set of pages contained in this wizard.
* @return Iterator
*/
public Iterator getPages()
{
public Iterator getPages() {
ArrayList pages = new ArrayList();
firstWizardPage = new FirstWizardPage(this);
firstWizardPage = new FirstWizardPage(registration, wizardContainer);
pages.add(firstWizardPage);
return pages.iterator();
}
/**
* Returns the set of data that user has entered through this wizard.
* @return Iterator
*/
public Iterator getSummary()
{
public Iterator getSummary() {
Hashtable summaryTable = new Hashtable();
/*
* Hashtable arranges the entries alphabetically so the order of
* appearance is:
* Hashtable arranges the entries alphabetically so the order
* of appearance is
* - Computer Name / IP
* - Port
* - User ID
*/
summaryTable.put("Account ID", registration.getAccountID());
summaryTable.put("Known Hosts", registration.getKnownHostsFile());
summaryTable.put("Identity", registration.getIdentityFile());
return summaryTable.entrySet().iterator();
}
/**
* Installs the account created through this wizard.
* @return ProtocolProviderService
*/
public ProtocolProviderService finish()
{
public ProtocolProviderService finish() {
firstWizardPage = null;
ProtocolProviderFactory factory
= SSHAccRegWizzActivator.getSSHProtocolProviderFactory();
= SSHAccRegWizzActivator.getSSHProtocolProviderFactory();
return this.installAccount(factory,
registration.getAccountID());
registration.getAccountID());
}
/**
* Creates an account for the given Account ID, Identity File and Known
* Hosts File
*
* @param providerFactory the ProtocolProviderFactory which will create
* the account
* @param user the user identifier
* @param user the user identifier
* @return the <tt>ProtocolProviderService</tt> for the new account.
*/
public ProtocolProviderService installAccount(
ProtocolProviderFactory providerFactory,
String user)
{
ProtocolProviderFactory providerFactory,
String user) {
Hashtable accountProperties = new Hashtable();
accountProperties.put(ProtocolProviderFactorySSHImpl.IDENTITY_FILE,
registration.getIdentityFile());
registration.getIdentityFile());
accountProperties.put(ProtocolProviderFactorySSH.KNOWN_HOSTS_FILE,
String.valueOf(registration.getKnownHostsFile()));
if (isModification)
{
providerFactory.uninstallAccount(protocolProvider.getAccountID());
this.protocolProvider = null;
this.isModification = false;
}
try
{
String.valueOf(registration.getKnownHostsFile()));
try {
AccountID accountID = providerFactory.installAccount(
user, accountProperties);
user, accountProperties);
ServiceReference serRef = providerFactory
.getProviderForAccount(accountID);
.getProviderForAccount(accountID);
protocolProvider = (ProtocolProviderService)
SSHAccRegWizzActivator.bundleContext
.getService(serRef);
}
catch (IllegalArgumentException exc)
{
SSHAccRegWizzActivator.getUIService().getPopupDialog()
.showMessagePopupDialog(
exc.getMessage(),
Resources.getString("error"),
PopupDialog.ERROR_MESSAGE);
}
catch (IllegalStateException exc)
{
SSHAccRegWizzActivator.getUIService().getPopupDialog()
.showMessagePopupDialog(
exc.getMessage(),
Resources.getString("error"),
PopupDialog.ERROR_MESSAGE);
SSHAccRegWizzActivator.bundleContext
.getService(serRef);
} catch (IllegalArgumentException exc) {
new ErrorDialog(null, "Error", exc.getMessage(), exc).showDialog();
} catch (IllegalStateException exc) {
new ErrorDialog(null, "Error", exc.getMessage(), exc).showDialog();
}
return protocolProvider;
}
/**
* Fills the UserID and Password fields in this panel with the data coming
* Fills the UserID and Password fields in this panel with the data comming
* from the given protocolProvider.
* @param protocolProvider The <tt>ProtocolProviderService</tt> to load the
* data from.
*/
public void loadAccount(ProtocolProviderService protocolProvider)
{
this.isModification = true;
public void loadAccount(ProtocolProviderService protocolProvider) {
this.protocolProvider = protocolProvider;
this.registration = new SSHAccountRegistration();
this.firstWizardPage.loadAccount(protocolProvider);
}
/**
* Indicates if this wizard is opened for modification or for creating a
* new account.
*
* @return <code>true</code> if this wizard is opened for modification and
* <code>false</code> otherwise.
*/
public boolean isModification()
{
return isModification;
}
/**
* Returns the wizard container, where all pages are added.
*
* @return the wizard container, where all pages are added
*/
public WizardContainer getWizardContainer()
{
return wizardContainer;
}
/**
* Returns the registration object, which will store all the data through
* the wizard.
*
* @return the registration object, which will store all the data through
* the wizard
*/
public SSHAccountRegistration getRegistration()
{
return registration;
isModification = true;
}
/**
* Returns the size of this wizard.
* @return the size of this wizard
*/
public Dimension getSize()
{
public Dimension getSize() {
return new Dimension(600, 500);
}
/**
* Returns the identifier of the page to show first in the wizard.
* @return the identifier of the page to show first in the wizard.
* Returns the identifier of the first account registration wizard page.
* This method is meant to be used by the wizard container to determine,
* which is the first page to show to the user.
*
* @return the identifier of the first account registration wizard page
*/
public Object getFirstPageIdentifier()
{
public Object getFirstPageIdentifier() {
return firstWizardPage.getIdentifier();
}
/**
* Returns the identifier of the page to show last in the wizard.
* @return the identifier of the page to show last in the wizard.
*/
public Object getLastPageIdentifier()
{
public Object getLastPageIdentifier() {
return firstWizardPage.getIdentifier();
}
}

@ -5,7 +5,6 @@ identityFile=Identitity File:
knownHosts=Known Hosts:
accountDetails=SSH Account Details
existingAccount=* The account you entered is already installed.
error=Error
protocolIcon=resources/images/protocol/ssh/ssh-online.png
pageImage=resources/images/protocol/ssh/ssh64x64.png

@ -74,6 +74,11 @@ public interface ProtocolNames
* The RSS protocol.
*/
public static final String RSS = "RSS";
/**
* The SSH protocol.
*/
public static final String SSH = "SSH";
/**
* The Gibberish protocol.

Loading…
Cancel
Save