comparison 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
comparison
equal deleted inserted replaced
19:f2a745ca0fbc 20:fc8c202cda87
57 57
58 from logging import debug, info, error 58 from logging import debug, info, error
59 from twisted.internet import protocol, reactor 59 from twisted.internet import protocol, reactor
60 from twisted.protocols.basic import FileSender 60 from twisted.protocols.basic import FileSender
61 from twisted.words.xish import domish 61 from twisted.words.xish import domish
62 from twisted.web.client import getPage
62 import struct 63 import struct
63 from binascii import hexlify 64 import urllib
64 import hashlib, pdb 65 import hashlib, pdb
65 66
66 from zope.interface import implements 67 from zope.interface import implements
67 68
68 try: 69 try:
452 implements(iwokkel.IDisco) 453 implements(iwokkel.IDisco)
453 454
454 params = """ 455 params = """
455 <params> 456 <params>
456 <category name="File Transfert"> 457 <category name="File Transfert">
457 <param name="IP" value="192.168.0.10" type="string" /> 458 <param name="IP" value='0.0.0.0' default_cb='yes' type="string" />
458 <param name="Port" value="28915" type="string" /> 459 <param name="Port" value="28915" type="string" />
459 </category> 460 </category>
460 </params> 461 </params>
461 """ 462 """
462 463
463 def __init__(self, host): 464 def __init__(self, host):
464 info("Plugin XEP_0065 initialization") 465 info("Plugin XEP_0065 initialization")
465 self.host = host 466 self.host = host
466 debug("registering") 467 debug("registering")
467 self.server_factory = Socks5ServerFactory() 468 self.server_factory = Socks5ServerFactory()
468 self.server_factory.protocol.host = self.host #needed for progress CB 469 self.server_factory.protocol.host = self.host #needed for progress CB
469 self.client_factory = Socks5ClientFactory() 470 self.client_factory = Socks5ClientFactory()
470 host.memory.import_params(self, XEP_0065.params) 471 host.memory.importParams(self, XEP_0065.params)
472 host.memory.setDefault("IP", "File Transfert", self.getExternalIP)
471 port = int(self.host.memory.getParamV("Port", "File Transfert")) 473 port = int(self.host.memory.getParamV("Port", "File Transfert"))
472 info("Launching Socks5 Stream server on port %d", port) 474 info("Launching Socks5 Stream server on port %d", port)
473 reactor.listenTCP(port, self.server_factory) 475 reactor.listenTCP(port, self.server_factory)
476
477 def getExternalIP(self):
478 """Return IP visible from outside, by asking to a website"""
479 return getPage("http://www.goffi.org/sat_tools/get_ip.php")
474 480
475 def connectionInitialized(self): 481 def connectionInitialized(self):
476 self.xmlstream.addObserver(BS_REQUEST, self.getFile) 482 self.xmlstream.addObserver(BS_REQUEST, self.getFile)
477 483
478 484