IPPlugin help

I was wondering if anyone had any luck with the IPPlugin for Openfire.

I would like to use the plugin so I can retrieve IP addresses of JID’s

to use in the spawning of Dameware (a remote PC tool) to essentially

auto-connect to a user on Spark. I have the Spark plugin working so it

can spawn dameware by right-clicking a user and selecting "Connect via

Dameware", but thats it.

This is the code snippet I am using to generate the custom IQ packet:

XMPPConnection conn = SparkManager.getConnection();
IQ registerIQ = new IQ () {
public String getChildElementXML() {
return "<query xmlns=\"nu:john:ip\">" +
"<data>me@jabber.server/spark</data> \n" +
"</query>";
}
};
registerIQ.setType(IQ.Type.GET);
conn.sendPacket(registerIQ);

This is what is sent:

<iq id="MW8bP-129" type="get">
  <query xmlns="nu:john:ip">
    <data>me@jabber.server/spark</data> </query>
</iq>

This is what is returned:

<iq id="MW8bP-129" to="me@jabber.server/spark" type="error">
  <error code="503" type="CANCEL">
    <service-unavailable xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"></service-unavailable>
  </error>
</iq>

Any help/suggestions would be greatly appreciated!!! Thanks!

Brandon

Hey Brandon,

You should try to connect the developer of the plugin. I don’t think the plugin actually works (at least the version available in sourceforge from February 9, 2007). I see that the logic is in place but the plugin is not correctly adding its service to the server. Bottom line, that logic is never used.

Regards,

– Gato

Thanks Gato!

I figured something of the sort. What would be the best way for me to implement something similar to the IPPlugin, or is there something already in place I could use?

Thanks again,

Brandon

Hey Brandon,

Probably the fastest solution would be to get the source code of the plugin and finish it. I would highly recommend adding permission control and changing the namespace being used. The plugin is now trying to work as an IQHandler. I think that it should work as a component. You can see how the broadcast or search plugins work to see a running example of components in Openfire. In a few hours you should have the new plugin running.

– Gato

Sounds good! I currently have the source and do see it using the IQHandler method. I just didn’t know it wasn’t the best way to go about things :). I’m sure I can figure out how to get it running as a component. Thank you for your help, and quick response!

Brandon

Hi Brandon,

I wrote the plugin and posted it on Sourceforge, but I never got around to write the client part using it (which makes me a moron since I just assumed everything worked). I hope you had some use of the code anyway, and figure out how to make it work for you. I’ll be happy to help in any way I can but Gato seems to have already suggested a solution (thanx btw) :).

Cheers,

/John

Hey John,

The plugin is IDEAL for what I need in my environment (more specifically for our desktop support group). I appreciate your work already put into the project because it really helps me through the process. My java skills are definitely not up to par at the moment so this is a good way to hone them. Although, I am sure I will be updating this thread will help requests.

Thanks guys,

Brandon

I have made some process in converting it to a component style plugin! But I have run into a snag.

import org.xmpp.packet.IQ;
import org.xmpp.packet.JID;
import org.xmpp.packet.Packet;
import org.xmpp.packet.PacketExtension;
import org.xmpp.packet.PacketError; .... private IQ handleIQ(IQ packet) { ....
String ip = "";
PacketExtension ext = packet.getExtension("data","jabber:iq:ip");
String jid = ext.getElement().getText(); ...
}

I cannot get this to work! The packet.getExtension() returns null everytime (even if I change the namespace to “”). If I print out packet.toString() or toXML() I get the whole packet. I am sure it is something simple. I am still sending the IQ get packet as before (minus the change of namespace to jabber:iq:ip ).

Any help is greatly appreciated!

Thanks,

Brandon

Hey Brandon,

Do not use getExtension(String name, String namespace) unless you have created your own PacketExtension and registed it. You can instead just get the dom4j Element of the IQ packet by using IQ#getChildElement(). It will return the fist dom4j element inside of the IQ packet (which should always be 1 or 0).

Regards,

– Gato

Thanks Gato – I think this fixed it!

Element ext = packet.getChildElement();
String jid = ext.elementText("data");

You might want to check that the IQ packet is of type GET and that it does contain a child element. Moreover, you might want to check that the namespace is correct too. Ignore IQ packets of type RESULT or ERROR and in any other case return an IQ error. Even if you have an Exception you have to return an IQ of type error. IQ senders expect an IQ response.

– Gato

Hey guys,

I developed a plugin that returns the IP of a client as well as geo information (latitude, longitude, etc.). The code for that is located here: http://www.igniterealtime.org/community/message/126666#126666

My plugin was slightly different in that it was written for use with a web app where the IP from the client session was the IP of the server where the web app was located. So, the IP had to be set from the client initiating the XMPP session. It would be set every time a user logged in using code like:

GEOIQ geoRequest = new GEOIQ();

geoRequest.setType(IQ.Type.SET);

geoRequest.setTo(“jabberServer.com”);

geoRequest.setJid(jidValue);

geoRequest.setIp(request.getRemoteAddr());

You don’t need to do that since your ClientSession should have a connection with the right IP of the client. I modified the attached GEOIQHandler to use the session IP if it wasn’t explicitly set by code like that above. Note I didn’t compile or test this changed handler code (but the code in the referenced append was tested and worked well on the server and client) but it should work. Let me know…

Thanks,

Jay
GEOIQHandler.java (4268 Bytes)

Thanks Jay!

I haven’t been able to check out what you have but I probably should have to see how you did the response packet with the server. I am having an issue with this.

This is what I have:

//create the resultIQ packet from the sent packet
IQ reply = IQ.createResultIQ(packet);
Element childElement = packet.getChildElement();
String namespace = childElement.getNamespaceURI();
Element childElementCopy = packet.getChildElement().createCopy();
reply.setChildElement(childElementCopy); ..... verify packet code..... //return packet generation Element identity = childElementCopy.addElement("ip");
             identity.addText(ip);
System.out.println(reply); ...else statement for error.... //returns the generated packet
return reply;

Now the System.out.println(reply) shows this as the packet:

<iq type="result" id="A2nT4-80" from="ipplugin.sparkserver.com" to="me@sparkserver.com/spark">
  <query xmlns="jabber:iq:ip">
    <data>username@sparkserver.com/spark</data>      <ip>correct_ip_here</ip>
  </query>
</iq>

Now this is where it gets weird…in Spark the response is shown as this from WITHIN the Smack “All Packets” debugger window:

<iq id="282b6-78" to="me@sparkserver.com/spark" from="ipplugin.sparkserver.com" type="result"/>

BUT if I look at “Raw Received Packets” in the Smack debugger window I show that this was received:

<iq type="result" id="282b6-78" from="ipplugin.sparkserver.com" to="me@sparkserver.com/spark"><query xmlns="jabber:iq:ip"><data>username@sparkserver.com/spark</data> <ip>correct_ip_here</ip></query></iq>

There must be an issue with how I am generating my XML so Spark/Smack doesn’t properly handle it? I don’t know.

Thanks for all your help guys and sorry for the long post!

Brandon

Hey Brandon,

You are doing everything in the correct way. Smack is receiving the XML from the server (as seen in the raw tab) but it does not know how to parse it. That is your last step that you need to implement. You need to create a new IQProvider in Smack and register it. Read this document for more information.

Regards,

– Gato

Ahh, I knew that ! I had read it a 100x it just never clicked.

Thanks Dom – its been a crazy couple of weeks for me.

Brandon