Mercurial > libervia-backend
diff plugins/plugin_xep_0065.py @ 20:fc8c202cda87
refactoring: using xml params part IV (default values)
- File Transfert/IP is now set by default to the ip externally visible
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 08 Nov 2009 00:11:00 +0100 |
parents | f2a745ca0fbc |
children | 633c5ed65701 |
line wrap: on
line diff
--- a/plugins/plugin_xep_0065.py Sat Nov 07 21:23:28 2009 +0100 +++ b/plugins/plugin_xep_0065.py Sun Nov 08 00:11:00 2009 +0100 @@ -59,8 +59,9 @@ from twisted.internet import protocol, reactor from twisted.protocols.basic import FileSender from twisted.words.xish import domish +from twisted.web.client import getPage import struct -from binascii import hexlify +import urllib import hashlib, pdb from zope.interface import implements @@ -454,12 +455,12 @@ params = """ <params> <category name="File Transfert"> - <param name="IP" value="192.168.0.10" type="string" /> + <param name="IP" value='0.0.0.0' default_cb='yes' type="string" /> <param name="Port" value="28915" type="string" /> </category> </params> """ - + def __init__(self, host): info("Plugin XEP_0065 initialization") self.host = host @@ -467,11 +468,16 @@ self.server_factory = Socks5ServerFactory() self.server_factory.protocol.host = self.host #needed for progress CB self.client_factory = Socks5ClientFactory() - host.memory.import_params(self, XEP_0065.params) + host.memory.importParams(self, XEP_0065.params) + host.memory.setDefault("IP", "File Transfert", self.getExternalIP) port = int(self.host.memory.getParamV("Port", "File Transfert")) info("Launching Socks5 Stream server on port %d", port) reactor.listenTCP(port, self.server_factory) + def getExternalIP(self): + """Return IP visible from outside, by asking to a website""" + return getPage("http://www.goffi.org/sat_tools/get_ip.php") + def connectionInitialized(self): self.xmlstream.addObserver(BS_REQUEST, self.getFile)