def plugin_init(self): """ Start the XEP-0199 plugin. """ self.keepalive = self.config.get('keepalive', False) self.frequency = float(self.config.get('frequency', 300)) self.timeout = self.config.get('timeout', 30) register_stanza_plugin(Iq, Ping) self.xmpp.register_handler( Callback('Ping', StanzaPath('iq@type=get/ping'), self._handle_ping)) if self.keepalive: self.xmpp.add_event_handler('session_start', self._handle_keepalive, threaded=True) self.xmpp.add_event_handler('session_end', self._handle_session_end) self.xmpp['xep_0030'].add_feature(Ping.namespace)
def plugin_init(self): """ Start the XEP-0199 plugin. """ self.description = 'XMPP Ping' self.xep = '0199' self.stanza = stanza self.keepalive = self.config.get('keepalive', False) self.frequency = float(self.config.get('frequency', 300)) self.timeout = self.config.get('timeout', 30) register_stanza_plugin(Iq, Ping) self.xmpp.register_handler( Callback('Ping', StanzaPath('iq@type=get/ping'), self._handle_ping)) if self.keepalive: self.xmpp.add_event_handler('session_start', self._handle_keepalive, threaded=True)
def __init__(self, user, password, host, nick, room_passwd=None): sleekxmpp.ClientXMPP.__init__(self, user, password) #Initially the values are undefined, will either be provided #by admin via XMPP message or existing cached values will be #used self.room = None self.ip4 = None self.uid = None self.nick = nick #dict for keeping track of JID's and their #connection status. ie. req_send #,resp_recvd etc self.xmpp_peers = {} #dict for keeping track of peer's xmpp_overlay status self.peer_xmpp_status = {} #uid-jid mapping,key = uid, val = jid self.uid_jid = {} #register new plugin stanza and the handler #for , whenever a matching #msg will be rcvd on xmpp stream #MsgListener method will be triggered. register_stanza_plugin(Message, Ipop_Msg) self.registerHandler( Callback('Ipop', StanzaPath('message/Ipop'), self.MsgListener)) #Register event handler for session #initialization/called after session #with xmpp server established. self.add_event_handler("session_start", self.start) #Register handlers for groupchat messages and MuC invitations, #any invitation will be accepted automatically self.add_event_handler("groupchat_message", self.muc_message) self.add_event_handler("groupchat_invite", self.accept_invite) #Initialize other parameters self.user = user self.password = password self.room_passwd = room_passwd self.host = host self.uid_ip_table = {}
def __init__(self, CFxHandle, paramDict, ModuleName): ControllerModule.__init__(self, CFxHandle, paramDict, ModuleName) self.xmpp_peers = defaultdict(int) # need to maintain uid<->jid mapping to route xmpp messages. self.uid_jid = {} self.xmpp_username = self.CMConfig.get("username") self.xmpp_passwd = self.CMConfig.get("password") self.xmpp_host = self.CMConfig.get("xmpp_host") self.uid = "" # initialize the base Xmpp client class sleekxmpp.ClientXMPP.__init__(self, self.xmpp_username, self.xmpp_passwd) # register a new plugin stanza and handler for it, # whenever a matching message will be received on # the xmpp stream , registered handler will be called. register_stanza_plugin(Message, Ipop_Msg) self.registerHandler( Callback('Ipop', StanzaPath('message/Ipop'), self.MsgListener)) # Register event handler for session start self.add_event_handler("session_start", self.start) # calculate UID, for the meantime # address mapping self.uid_ip4_table = {} self.ip4_uid_table = {} # populate uid_ip4_table and ip4_uid_table with all UID and IPv4 # mappings within the /16 subnet parts = self.CMConfig["ip4"].split(".") ip_prefix = parts[0] + "." + parts[1] + "." for i in range(0, 255): for j in range(0, 255): ip4 = ip_prefix + str(i) + "." + str(j) uid = fxlib.gen_uid(ip4) self.uid_ip4_table[uid] = ip4 self.ip4_uid_table[ip4] = uid self.uid = self.ip4_uid_table[self.CMConfig["ip4"]] # Start xmpp handling thread self.xmpp_handler()
def __init__(self, CFxHandle, paramDict, ModuleName): ControllerModule.__init__(self, CFxHandle, paramDict, ModuleName) # keeps track of last recvd advertisement and if node is active on XMPP. self.xmpp_peers = defaultdict(lambda: [0, False]) # need to maintain uid<->jid mapping to route xmpp messages. self.uid_jid = {} # FullJID,Knows my UID,num(Correct advts recvd) self.jid_uid = defaultdict(lambda: ['', False, 1]) self.xmpp_username = self.CMConfig.get("Username") self.xmpp_passwd = self.CMConfig.get("Password", "None") self.xmpp_host = self.CMConfig.get("AddressHost") self.xmpp_port = self.CMConfig.get("Port") self.vpn_type = self.CFxHandle.queryParam("CFx", "Model") self.interface_name = self.CMConfig.get("TapName") self.uid = "" self.update_peerlist = False # time of last recvd xmpp advt. self.last_sent_advt = 0 # keeps track of if xmpp advt recvd in interval self.xmpp_advt_recvd = True # Initial ADVT Delay self.INITIAL_ADVT_DELAY = 5 # interval between sending advertisements self.advt_delay = self.INITIAL_ADVT_DELAY # Maximum delay between advertisements is 10 minutes self.MAX_ADVT_DELAY = 600 # initialize the base Xmpp client class, handle login/authentication. if self.CMConfig.get("AuthenticationMethod") == "x509" and \ (self.xmpp_username != None \ or self.xmpp_passwd != None): raise RuntimeError( "x509 Authentication Error: Username/Password in IPOP configuration file." ) use_tls = True if self.CMConfig.get("AuthenticationMethod") == "x509": sleekxmpp.ClientXMPP.__init__(self, self.xmpp_host, self.xmpp_passwd, sasl_mech='EXTERNAL') self.ssl_version = ssl.PROTOCOL_TLSv1 self.ca_certs = self.CMConfig.get("TrustStore") self.certfile = self.CMConfig.get( "CertDirectory") + self.CMConfig.get("CertFile") self.keyfile = self.CMConfig.get( "CertDirectory") + self.CMConfig.get("Keyfile") else: sleekxmpp.ClientXMPP.__init__(self, self.xmpp_username, self.xmpp_passwd, sasl_mech='PLAIN') if self.CMConfig.get("AcceptUntrustedServer") == True: self['feature_mechanisms'].unencrypted_plain = True use_tls = False else: self.ca_certs = self.CMConfig.get("TrustStore") # register a new plugin stanza and handler for it, # whenever a matching message will be received on # the xmpp stream , registered handler will be called. register_stanza_plugin(Message, Ipop_Msg) self.registerHandler( Callback('Ipop', StanzaPath('message/Ipop'), self.MsgListener)) # Register event handler for session start self.add_event_handler("session_start", self.start) self.add_event_handler("roster_update", self.deletepeerjid) # populate uid_ip4_table and ip4_uid_table with all UID and IPv4 # mappings within the /16 subnet if (self.vpn_type == "GroupVPN"): ipop_interfaces = self.CFxHandle.queryParam("Tincan", "Vnets") for interface_details in ipop_interfaces: if interface_details["TapName"] == self.interface_name: self.uid = interface_details["uid"] elif (self.vpn_type == "SocialVPN"): self.registerCBT('Watchdog', 'QUERY_IPOP_STATE') # Start xmpp handling thread self.xmpp_handler()
def __init__(self, jid, password, plugin_config={}, plugin_whitelist=[], escape_quotes=True, sasl_mech=None, lang='en'): BaseXMPP.__init__(self, jid, 'jabber:client') self.set_jid(jid) self.escape_quotes = escape_quotes self.plugin_config = plugin_config self.plugin_whitelist = plugin_whitelist self.default_port = 5222 self.default_lang = lang self.credentials = {} self.password = password self.stream_header = "<stream:stream to='%s' %s %s %s %s>" % ( self.boundjid.host, "xmlns:stream='%s'" % self.stream_ns, "xmlns='%s'" % self.default_ns, "xml:lang='%s'" % self.default_lang, "version='1.0'") self.stream_footer = "</stream:stream>" self.features = set() self._stream_feature_handlers = {} self._stream_feature_order = [] self.dns_service = 'xmpp-client' #TODO: Use stream state here self.authenticated = False self.sessionstarted = False self.bound = False self.bindfail = False self.add_event_handler('connected', self._handle_connected) self.add_event_handler('session_bind', self._handle_session_bind) self.register_stanza(StreamFeatures) self.register_handler( Callback('Stream Features', MatchXPath('{%s}features' % self.stream_ns), self._handle_stream_features)) self.register_handler( Callback('Roster Update', StanzaPath('iq@type=set/roster'), self._handle_roster)) # Setup default stream features self.register_plugin('feature_starttls') self.register_plugin('feature_bind') self.register_plugin('feature_session') self.register_plugin('feature_rosterver') self.register_plugin('feature_preapproval') self.register_plugin( 'feature_mechanisms', pconfig={'use_mech': sasl_mech} if sasl_mech else None)
def plugin_init(self): self.xmpp.register_handler( Callback("Deepin Qun", StanzaPath("iq/qun_query"), self.handle_qun)) register_stanza_plugin(Iq, QueryElement)
def plugin_init(self): self.xep = '0060' self.description = 'Publish-Subscribe' self.stanza = stanza self.xmpp.registerHandler( Callback('pubsub get items', StanzaPath('iq@type=get/pubsub/items'), self._handle_get_items)) self.xmpp.registerHandler( Callback('pubsub set items', StanzaPath('iq@type=set/pubsub/publish'), self._handle_set_items)) self.xmpp.registerHandler( Callback('pubsub create node', StanzaPath('iq@type=set/pubsub/create'), self._handle_create_node)) self.xmpp.registerHandler( Callback('pubsub delete node', StanzaPath('iq@type=set/pubsub/delete'), self._handle_delete_node)) self.xmpp.registerHandler( Callback('pubsub retract node', StanzaPath('iq@type=set/pubsub/retract'), self._handle_retract_node)) self.xmpp.registerHandler( Callback('pubsub_owner get node config', StanzaPath('iq@type=get/pubsub_owner/configure'), self._handle_get_node_config)) self.xmpp.registerHandler( Callback('pubsub_owner set node config', StanzaPath('iq@type=set/pubsub_owner/configure'), self._handle_set_node_config)) self.xmpp.registerHandler( Callback('pubsub subscribe', StanzaPath('iq@type=set/pubsub/subscribe'), self._handle_subscribe)) self.xmpp.registerHandler( Callback('pubsub_owner set subscriptions', StanzaPath('iq@type=set/pubsub_owner/subscriptions'), self._handle_owner_set_subscriptions)) self.xmpp.registerHandler( Callback('pubsub_owner get subscriptions', StanzaPath('iq@type=get/pubsub_owner/subscriptions'), self._handle_owner_get_subscriptions)) self.xmpp.registerHandler( Callback('pubsub unsubscribe', StanzaPath('iq@type=set/pubsub/unsubscribe'), self._handle_unsubscribe)) self.xmpp.registerHandler( Callback('message event', StanzaPath('message/pubsub_event'), self._handle_message_event)) self.xmpp.registerHandler( Callback('pubsub_owner set affiliations', StanzaPath('iq@type=set/pubsub_owner/affiliations'), self._handle_set_affiliations)) self.xmpp.registerHandler( Callback('pubsub_owner get affiliations', StanzaPath('iq@type=get/pubsub_owner/affiliations'), self._handle_get_affiliations))
def plugin_init(self): self.xmpp.register_handler( Callback("Disco Brother", StanzaPath("iq/disco_brother"), self.handle_disco_brother)) register_stanza_plugin(Iq, DiscoBrother)
def __init__(self,CFxHandle,paramDict,ModuleName): ControllerModule.__init__(self,CFxHandle,paramDict,ModuleName) # keeps track of last recvd advertisement and if node is active on XMPP. self.xmpp_peers = defaultdict(lambda:[0,False]) # need to maintain uid<->jid mapping to route xmpp messages. self.uid_jid = {} # FullJID,Knows my UID,num(Correct advts recvd) self.jid_uid = defaultdict(lambda:['',False,1]) self.xmpp_username = self.CMConfig.get("xmpp_username") self.xmpp_passwd = self.CMConfig.get("xmpp_password") self.xmpp_host = self.CMConfig.get("xmpp_host") self.xmpp_port = self.CMConfig.get("xmpp_port") self.vpn_type = self.CFxHandle.queryParam("vpn_type") self.uid = "" # time of last recvd xmpp advt. self.last_sent_advt = 0 # keeps track of if xmpp advt recvd in interval self.xmpp_advt_recvd = True # Initial ADVT Delay self.INITIAL_ADVT_DELAY =5 # interval between sending advertisements self.advt_delay = self.INITIAL_ADVT_DELAY # Maximum delay between advertisements is 10 minutes self.MAX_ADVT_DELAY = 600 # initialize the base Xmpp client class, handle login/authentication. if self.CMConfig.get("xmpp_authentication_method")=="x509" and \ (self.CMConfig.get("xmpp_username")!= None \ or self.CMConfig.get("xmpp_password")!= None): raise RuntimeError("x509 Authentication Exception. Username or Password present in IPOP configuration file.") use_tls = True if self.CMConfig.get("xmpp_authentication_method")=="x509": sleekxmpp.ClientXMPP.__init__(self,self.xmpp_host,self.xmpp_passwd,sasl_mech='EXTERNAL') self.ssl_version = ssl.PROTOCOL_TLSv1 self.ca_certs = self.CMConfig.get("truststore") self.certfile = self.CMConfig.get("certdirectory")+self.CMConfig.get("certfile") self.keyfile = self.CMConfig.get("certdirectory")+self.CMConfig.get("keyfile") else: sleekxmpp.ClientXMPP.__init__(self, self.xmpp_username, self.xmpp_passwd, sasl_mech='PLAIN') if self.CMConfig.get("xmpp_accept_untrusted_server")==True: self['feature_mechanisms'].unencrypted_plain = True use_tls = False else: self.ca_certs = self.CMConfig.get("truststore") # register a new plugin stanza and handler for it, # whenever a matching message will be received on # the xmpp stream , registered handler will be called. register_stanza_plugin(Message, Ipop_Msg) self.registerHandler( Callback('Ipop', StanzaPath('message/Ipop'), self.MsgListener)) # Register event handler for session start self.add_event_handler("session_start",self.start) # calculate UID, for the meantime # address mapping self.uid_ip4_table = {} self.ip4_uid_table = {} # populate uid_ip4_table and ip4_uid_table with all UID and IPv4 # mappings within the /16 subnet if (self.vpn_type == "GroupVPN"): parts = self.CFxHandle.queryParam("ip4").split(".") ip_prefix = parts[0] + "." + parts[1] + "." for i in range(0, 255): for j in range(0, 255): ip4 = ip_prefix + str(i) + "." + str(j) uid = fxlib.gen_uid(ip4) self.uid_ip4_table[uid] = ip4 self.ip4_uid_table[ip4] = uid self.uid = self.ip4_uid_table[self.CFxHandle.queryParam("ip4")] elif (self.vpn_type == "SocialVPN"): self.registerCBT('Watchdog', 'QUERY_IPOP_STATE') # Start xmpp handling thread self.xmpp_handler()
def plugin_init(self): self.node_event_map = {} self.xmpp.registerHandler( Callback('pubsub get items', StanzaPath('iq@type=get/pubsub/items'), self._handle_get_items)) self.xmpp.registerHandler( Callback('pubsub set items', StanzaPath('iq@type=set/pubsub/publish'), self._handle_set_items)) self.xmpp.registerHandler( Callback('pubsub create node', StanzaPath('iq@type=set/pubsub/create'), self._handle_create_node)) self.xmpp.registerHandler( Callback('pubsub delete node', StanzaPath('iq@type=set/pubsub/delete'), self._handle_delete_node)) self.xmpp.registerHandler( Callback('pubsub retract node', StanzaPath('iq@type=set/pubsub/retract'), self._handle_retract_node)) self.xmpp.registerHandler( Callback('pubsub_owner get node config', StanzaPath('iq@type=get/pubsub_owner/configure'), self._handle_get_node_config)) self.xmpp.registerHandler( Callback('pubsub_owner set node config', StanzaPath('iq@type=set/pubsub_owner/configure'), self._handle_set_node_config)) self.xmpp.registerHandler( Callback('pubsub subscribe', StanzaPath('iq@type=set/pubsub/subscribe'), self._handle_subscribe)) self.xmpp.registerHandler( Callback('pubsub_owner set subscriptions', StanzaPath('iq@type=set/pubsub_owner/subscriptions'), self._handle_owner_set_subscriptions)) self.xmpp.registerHandler( Callback('pubsub_owner get subscriptions', StanzaPath('iq@type=get/pubsub_owner/subscriptions'), self._handle_owner_get_subscriptions)) self.xmpp.registerHandler( Callback('pubsub unsubscribe', StanzaPath('iq@type=set/pubsub/unsubscribe'), self._handle_unsubscribe)) self.xmpp.registerHandler( Callback('message event', StanzaPath('message/pubsub_event'), self._handle_message_event)) self.xmpp.registerHandler( Callback('pubsub_owner set affiliations', StanzaPath('iq@type=set/pubsub_owner/affiliations'), self._handle_set_affiliations)) self.xmpp.registerHandler( Callback('pubsub_owner get affiliations', StanzaPath('iq@type=get/pubsub_owner/affiliations'), self._handle_get_affiliations)) self.xmpp['xep_0131'].supported_headers.add('SubID')