def sendCompletedForm(self, el, sessionid=None):
		to = el.getAttribute('from')
		ID = el.getAttribute('id')
		ulang = utils.getLang(el)
		
		iq = Element((None, 'iq'))
		iq.attributes = {'to': to, 'from': config.jid, 'type': 'result'}
		if ID:
			iq.attributes['id'] = ID
		command = iq.addElement('command')
		command.attributes = {
			'node': 'settings', 
			'xmlns': globals.COMMANDS, 
			'status': 'completed'
		}
		if sessionid:
			command.attributes['sessionid'] = sessionid
		else:
			command.attributes['sessionid'] = self.pytrans.makeMessageID()

		note = command.addElement('note', None, lang.get('settings_changed'))
		note.attributes['type'] = 'info'
		
		x = command.addElement('x')
		x.attributes = {'xmlns': 'jabber:x:data', 'type': 'form'}
		x.addElement('title', None, lang.get('command_Settings'))
		x.addElement('instructions', None, lang.get('settings_changed'))
		
		self.pytrans.send(iq)
Example #2
0
	def pwdChangeResults(self, results, el, sessionid, newpassword):
		to = el.getAttribute("from")
		toj = internJID(to)
		ID = el.getAttribute("id")
		ulang = utils.getLang(el)

		iq = Element((None, "iq"))
		iq.attributes["to"] = to
		iq.attributes["from"] = config.jid
		if ID:
			iq.attributes["id"] = ID
		iq.attributes["type"] = "result"

		command = iq.addElement("command")
		if sessionid:
			command.attributes["sessionid"] = sessionid
		else:
			command.attributes["sessionid"] = self.pytrans.makeMessageID()
		command.attributes["node"] = "changepassword"
		command.attributes["xmlns"] = globals.COMMANDS
		command.attributes["status"] = "completed"

		note = command.addElement("note")
		if results[3]:
			note.attributes["type"] = "error"
			note.addContent(lang.get("command_ChangePassword_Failed", ulang))
		else:
			note.attributes["type"] = "info"
			note.addContent(lang.get("command_Done", ulang))
			(username, oldpassword) = self.pytrans.xdb.getRegistration(toj.userhost())
			self.pytrans.xdb.setRegistration(toj.userhost(), username, newpassword)

		self.pytrans.send(iq)
Example #3
0
    def updateRegistration(self, incoming):
        # Grab the username, password
        ID = incoming.getAttribute("id")
        fro = incoming.getAttribute("from")
        LogEvent(INFO)
        source = internJID(fro).userhost()
        ulang = utils.getLang(incoming)
        username = None
        password = None

        for queryFind in incoming.elements():
            if (queryFind.name == "query"):
                for child in queryFind.elements():
                    try:
                        if (child.name == "username"):
                            username = child.__str__()
                        elif (child.name == "password"):
                            password = child.__str__()
                        elif (child.name == "remove"):
                            # The user wants to unregister the transport! Gasp!
                            LogEvent(INFO, "", "Unregistering.")
                            try:
                                self.removeRegInfo(source)
                                self.successReply(incoming)
                            except:
                                self.xdbErrorReply(incoming)
                                return
                            LogEvent(INFO, "", "Unregistered!")
                            return
                    except AttributeError, TypeError:
                        continue  # Ignore any errors, we'll check everything below
Example #4
0
    def sendRegistrationFields(self, incoming):
        # Construct a reply with the fields they must fill out
        ID = incoming.getAttribute("id")
        fro = incoming.getAttribute("from")
        LogEvent(INFO)
        reply = Element((None, "iq"))
        reply.attributes["from"] = config.jid
        reply.attributes["to"] = fro
        if ID:
            reply.attributes["id"] = ID
        reply.attributes["type"] = "result"
        query = reply.addElement("query")
        query.attributes["xmlns"] = "jabber:iq:register"
        instructions = query.addElement("instructions")
        ulang = utils.getLang(incoming)
        instructions.addContent(lang.get(ulang).registerText)
        userEl = query.addElement("username")
        passEl = query.addElement("password")

        # Check to see if they're registered
        result = self.getRegInfo(incoming.getAttribute("from"))
        if (result):
            username, password = result
            userEl.addContent(username)
            query.addElement("registered")

        self.pytrans.send(reply)
	def incomingIq(self, el):
		to = el.getAttribute("from")
		toj = internJID(to)
		ID = el.getAttribute("id")
		ulang = utils.getLang(el)

		sessionid = None
		email = None

		for command in el.elements():
			sessionid = command.getAttribute("sessionid")
			if command.getAttribute("action") == "cancel":
				self.pytrans.adhoc.sendCancellation("emaillookup", el, sessionid)
				return
			for child in command.elements():
				if child.name == "x" and child.getAttribute("type") == "submit":
					for field in child.elements():
						if field.name == "field" and field.getAttribute("var") == "email":
							for value in field.elements():
								if value.name == "value":
									email = value.__str__()

		if not self.pytrans.sessions.has_key(toj.userhost()) or not hasattr(self.pytrans.sessions[toj.userhost()].legacycon, "bos"):
			self.pytrans.adhoc.sendError("emaillookup", el, errormsg=lang.get("command_NoSession", ulang), sessionid=sessionid)
		elif email:
			self.lookupEmail(el, email, sessionid=sessionid)
		else:
			self.sendForm(el)
Example #6
0
    def sendRegistrationFields(self, incoming):
        # Construct a reply with the fields they must fill out
        LogEvent(INFO)
        reply = Element((None, "iq"))
        reply.attributes["from"] = config.jid
        reply.attributes["to"] = incoming.getAttribute("from")
        reply.attributes["id"] = incoming.getAttribute("id")
        reply.attributes["type"] = "result"
        query = reply.addElement("query")
        query.attributes["xmlns"] = globals.IQREGISTER
        instructions = query.addElement("instructions")
        ulang = utils.getLang(incoming)
        instructions.addContent(lang.get("registertext", ulang))
        userEl = query.addElement("username")
        passEl = query.addElement("password")

        # Check to see if they're registered
        source = internJID(incoming.getAttribute("from")).userhost()
        result = self.pytrans.xdb.getRegistration(source)
        if result:
            username, password = result
            if username != "local":
                userEl.addContent(username)
                query.addElement("registered")

        self.pytrans.send(reply)
Example #7
0
	def incomingIq(self, el):
		to = el.getAttribute("from")
		toj = internJID(to)
		ID = el.getAttribute("id")
		ulang = utils.getLang(el)

		sessionid = None
		email = None

		for command in el.elements():
			sessionid = command.getAttribute("sessionid")
			if command.getAttribute("action") == "cancel":
				self.pytrans.adhoc.sendCancellation("changeemail", el, sessionid)
				return
			for child in command.elements():
				if child.name == "x" and child.getAttribute("type") == "submit":
					for field in child.elements():
						if field.name == "field" and field.getAttribute("var") == "email":
							for value in field.elements():
								if value.name == "value":
									email = value.__str__()

		if not self.pytrans.sessions.has_key(toj.userhost()) or not hasattr(self.pytrans.sessions[toj.userhost()].legacycon, "bos"):
			self.pytrans.adhoc.sendError("changeemail", el, errormsg=lang.get("command_NoSession", ulang), sessionid=sessionid)
		elif email:
			self.changeEmail(el, email, sessionid)
		else:
			self.pytrans.sessions[toj.userhost()].legacycon.bos.getEmailAddress().addCallback(self.sendForm, el)
Example #8
0
    def incomingIq(self, el):
        to = el.getAttribute("from")
        toj = internJID(to)
        ID = el.getAttribute("id")
        ulang = utils.getLang(el)

        sessionid = None

        for command in el.elements():
            sessionid = command.getAttribute("sessionid")
            if command.getAttribute("action") == "cancel":
                self.pytrans.adhoc.sendCancellation("confirmaccount", el,
                                                    sessionid)
                return

        if not self.pytrans.sessions.has_key(toj.userhost()) or not hasattr(
                self.pytrans.sessions[toj.userhost()].legacycon, "bos"):
            self.pytrans.adhoc.sendError("confirmaccount",
                                         el,
                                         errormsg=lang.get(
                                             "command_NoSession", ulang),
                                         sessionid=sessionid)
        else:
            self.pytrans.sessions[
                toj.userhost()].legacycon.bos.confirmAccount().addCallback(
                    self.sendResponse, el, sessionid)
Example #9
0
    def pwdChangeResults(self, results, el, sessionid, newpassword):
        to = el.getAttribute("from")
        toj = internJID(to)
        ID = el.getAttribute("id")
        ulang = utils.getLang(el)

        iq = Element((None, "iq"))
        iq.attributes["to"] = to
        iq.attributes["from"] = config.jid
        if ID:
            iq.attributes["id"] = ID
        iq.attributes["type"] = "result"

        command = iq.addElement("command")
        if sessionid:
            command.attributes["sessionid"] = sessionid
        else:
            command.attributes["sessionid"] = self.pytrans.makeMessageID()
        command.attributes["node"] = "changepassword"
        command.attributes["xmlns"] = globals.COMMANDS
        command.attributes["status"] = "completed"

        note = command.addElement("note")
        if results[3]:
            note.attributes["type"] = "error"
            note.addContent(lang.get("command_ChangePassword_Failed", ulang))
        else:
            note.attributes["type"] = "info"
            note.addContent(lang.get("command_Done", ulang))
            (username,
             oldpassword) = self.pytrans.xdb.getRegistration(toj.userhost())
            self.pytrans.xdb.setRegistration(toj.userhost(), username,
                                             newpassword)

        self.pytrans.send(iq)
Example #10
0
	def emailChangeResults(self, results, el, sessionid):
		to = el.getAttribute("from")
		toj = internJID(to)
		ID = el.getAttribute("id")
		ulang = utils.getLang(el)

		iq = Element((None, "iq"))
		iq.attributes["to"] = to
		iq.attributes["from"] = config.jid
		if ID:
			iq.attributes["id"] = ID
		iq.attributes["type"] = "result"

		command = iq.addElement("command")
		if sessionid:
			command.attributes["sessionid"] = sessionid
		else:
			command.attributes["sessionid"] = self.pytrans.makeMessageID()
		command.attributes["node"] = "changeemail"
		command.attributes["xmlns"] = globals.COMMANDS
		command.attributes["status"] = "completed"

		note = command.addElement("note")
		if results[3]:
			note.attributes["type"] = "error"
			note.addContent(results[3][1])
		else:
			note.attributes["type"] = "info"
			note.addContent(lang.get("command_Done", ulang))

		self.pytrans.send(iq)
Example #11
0
	def incomingIq(self, el):
		to = el.getAttribute("from")
		toj = internJID(to)
		ID = el.getAttribute("id")
		ulang = utils.getLang(el)

		sessionid = None
		fmtsn = None

		for command in el.elements():
			sessionid = command.getAttribute("sessionid")
			if command.getAttribute("action") == "cancel":
				self.pytrans.adhoc.sendCancellation("formatscreenname", el, sessionid)
				return
			for child in command.elements():
				if child.name == "x" and child.getAttribute("type") == "submit":
					for field in child.elements():
						if field.name == "field" and field.getAttribute("var") == "fmtsn":
							for value in field.elements():
								if value.name == "value":
									fmtsn = value.__str__()

		if not self.pytrans.sessions.has_key(toj.userhost()) or not hasattr(self.pytrans.sessions[toj.userhost()].legacycon, "bos"):
			self.pytrans.adhoc.sendError("formatscreenname", el, errormsg=lang.get("command_NoSession", ulang), sessionid=sessionid)
		elif fmtsn:
			self.changeSNFormat(el, fmtsn, sessionid)
		else:
			self.pytrans.sessions[toj.userhost()].legacycon.bos.getFormattedScreenName().addCallback(self.sendForm, el)
Example #12
0
	def sendResponse(self, failure, el, sessionid=None):
		LogEvent(INFO)
		to = el.getAttribute("from")
		toj = internJID(to)
		ID = el.getAttribute("id")
		ulang = utils.getLang(el)

		iq = Element((None, "iq"))
		iq.attributes["to"] = to
		iq.attributes["from"] = config.jid
		if ID:
			iq.attributes["id"] = ID
		iq.attributes["type"] = "result"

		command = iq.addElement("command")
		if sessionid:
			command.attributes["sessionid"] = sessionid
		else:
			command.attributes["sessionid"] = self.pytrans.makeMessageID()
		command.attributes["node"] = "confirmaccount"
		command.attributes["xmlns"] = globals.COMMANDS
		command.attributes["status"] = "completed"

		note = command.addElement("note")
		if failure:
			note.attributes["type"] = "error"
			note.addContent(lang.get("command_ConfirmAccount_Failed", ulang))
		else:
			note.attributes["type"] = "info"
			note.addContent(lang.get("command_ConfirmAccount_Complete", ulang))

		self.pytrans.send(iq)
Example #13
0
	def snfmtChangeResults(self, results, el, sessionid):
		to = el.getAttribute("from")
		toj = internJID(to)
		ID = el.getAttribute("id")
		ulang = utils.getLang(el)

		iq = Element((None, "iq"))
		iq.attributes["to"] = to
		iq.attributes["from"] = config.jid
		if ID:
			iq.attributes["id"] = ID
		iq.attributes["type"] = "result"

		command = iq.addElement("command")
		if sessionid:
			command.attributes["sessionid"] = sessionid
		else:
			command.attributes["sessionid"] = self.pytrans.makeMessageID()
		command.attributes["node"] = "formatscreenname"
		command.attributes["xmlns"] = globals.COMMANDS
		command.attributes["status"] = "completed"

		note = command.addElement("note")
		if results[3]:
			note.attributes["type"] = "error"
			note.addContent(results[3][1])
		else:
			note.attributes["type"] = "info"
			note.addContent(lang.get("command_Done", ulang))

		self.pytrans.send(iq)
Example #14
0
	def incomingIq(self, el):
		itype = el.getAttribute("type")
		fro = el.getAttribute("from")
		froj = internJID(fro)
		to = el.getAttribute("to")
		ID = el.getAttribute("id")
		ulang = utils.getLang(el)

		LogEvent(INFO, msg="Looking for handler")

		node = None
		for child in el.elements():
			xmlns = child.uri
			node = child.getAttribute("node")

			handled = False
			if child.name == "query" and xmlns == globals.DISCO_INFO:
				if node and self.commands.has_key(node) and itype == "get":
					self.sendCommandInfoResponse(to=fro, ID=ID, node=node, ulang=ulang)
					handled = True
			elif child.name == "query" and xmlns == globals.DISCO_ITEMS:
				if node and self.commands.has_key(node) and itype == "get":
					self.sendCommandItemsResponse(to=fro, ID=ID, node=node, ulang=ulang)
					handled = True
			elif child.name == "command" and xmlns == globals.COMMANDS:
				if node and self.commands.has_key(node) and (itype == "set" or itype == "error"):
					self.commands[node](el)
					handled = True
			if not handled:
				LogEvent(WARN, msg="Unknown Ad-Hoc command received")
				self.pytrans.iq.sendIqError(to=fro, fro=config.jid, ID=ID, xmlns=xmlns, etype="cancel", condition="feature-not-implemented")
Example #15
0
	def sendSearchForm(self, el):
		LogEvent(INFO)
		ulang = utils.getLang(el)
		iq = Element((None, "iq"))
		iq.attributes["type"] = "result"
		iq.attributes["from"] = el.getAttribute("to")
		iq.attributes["to"] = el.getAttribute("from")
		if el.getAttribute("id"):
			iq.attributes["id"] = el.getAttribute("id")
		query = iq.addElement("query")
		query.attributes["xmlns"] = globals.IQSEARCH
		forminstr = query.addElement("instructions")
		forminstr.addContent(lang.get("searchnodataform", ulang))
		x = query.addElement("x")
		x.attributes["xmlns"] = globals.XDATA
		x.attributes["type"] = "form"
		title = x.addElement("title")
		title.addContent(lang.get("searchtitle", ulang))
		instructions = x.addElement("instructions")
		instructions.addContent(lang.get("searchinstructions", ulang))
		x.addChild(utils.makeDataFormElement("hidden", "FORM_TYPE", value="jabber:iq:search"))
		x.addChild(utils.makeDataFormElement("text-single", "email", "E-Mail Address"))
		x.addChild(utils.makeDataFormElement("text-single", "first", "First Name"))
		x.addChild(utils.makeDataFormElement("text-single", "middle", "Middle Name"))
		x.addChild(utils.makeDataFormElement("text-single", "last", "Last Name"))
		x.addChild(utils.makeDataFormElement("text-single", "maiden", "Maiden Name"))
		x.addChild(utils.makeDataFormElement("text-single", "nick", "Nickname"))
		x.addChild(utils.makeDataFormElement("text-single", "address", "Street Address"))
		x.addChild(utils.makeDataFormElement("text-single", "city", "City"))
		x.addChild(utils.makeDataFormElement("text-single", "state", "State"))
		x.addChild(utils.makeDataFormElement("text-single", "zip", "Zip Code"))
		x.addChild(utils.makeDataFormElement("text-single", "country", "Country"))
		x.addChild(utils.makeDataFormElement("text-single", "interest", "Interest"))

		self.pytrans.send(iq)
Example #16
0
    def sendResponse(self, failure, el, sessionid=None):
        LogEvent(INFO)
        to = el.getAttribute("from")
        toj = internJID(to)
        ID = el.getAttribute("id")
        ulang = utils.getLang(el)

        iq = Element((None, "iq"))
        iq.attributes["to"] = to
        iq.attributes["from"] = config.jid
        if ID:
            iq.attributes["id"] = ID
        iq.attributes["type"] = "result"

        command = iq.addElement("command")
        if sessionid:
            command.attributes["sessionid"] = sessionid
        else:
            command.attributes["sessionid"] = self.pytrans.makeMessageID()
        command.attributes["node"] = "confirmaccount"
        command.attributes["xmlns"] = globals.COMMANDS
        command.attributes["status"] = "completed"

        note = command.addElement("note")
        if failure:
            note.attributes["type"] = "error"
            note.addContent(lang.get("command_ConfirmAccount_Failed", ulang))
        else:
            note.attributes["type"] = "info"
            note.addContent(lang.get("command_ConfirmAccount_Complete", ulang))

        self.pytrans.send(iq)
Example #17
0
    def sendForm(self, el, sessionid=None, errormsg=None):
        to = el.getAttribute("from")
        ID = el.getAttribute("id")
        ulang = utils.getLang(el)

        iq = Element((None, "iq"))
        iq.attributes["to"] = to
        iq.attributes["from"] = config.jid
        if ID:
            iq.attributes["id"] = ID
        iq.attributes["type"] = "result"

        command = iq.addElement("command")
        if sessionid:
            command.attributes["sessionid"] = sessionid
        else:
            command.attributes["sessionid"] = self.pytrans.makeMessageID()
        command.attributes["node"] = "changepassword"
        command.attributes["xmlns"] = globals.COMMANDS
        command.attributes["status"] = "executing"

        if errormsg:
            note = command.addElement("note")
            note.attributes["type"] = "error"
            note.addContent(errormsg)

        actions = command.addElement("actions")
        actions.attributes["execute"] = "complete"
        actions.addElement("complete")

        x = command.addElement("x")
        x.attributes["xmlns"] = "jabber:x:data"
        x.attributes["type"] = "form"

        title = x.addElement("title")
        title.addContent(lang.get("command_ChangePassword", ulang))

        instructions = x.addElement("instructions")
        instructions.addContent(
            lang.get("command_ChangePassword_Instructions", ulang))

        oldpassword = x.addElement("field")
        oldpassword.attributes["type"] = "text-private"
        oldpassword.attributes["var"] = "oldpassword"
        oldpassword.attributes["label"] = lang.get(
            "command_ChangePassword_OldPassword", ulang)

        newpassword = x.addElement("field")
        newpassword.attributes["type"] = "text-private"
        newpassword.attributes["var"] = "newpassword"
        newpassword.attributes["label"] = lang.get(
            "command_ChangePassword_NewPassword", ulang)

        newpassworda = x.addElement("field")
        newpassworda.attributes["type"] = "text-private"
        newpassworda.attributes["var"] = "newpasswordagain"
        newpassworda.attributes["label"] = lang.get(
            "command_ChangePassword_NewPasswordAgain", ulang)

        self.pytrans.send(iq)
	def sendCommandList(self, el):
		to = el.getAttribute("from")
		toj_uh = internJID(to).userhost()
		ID = el.getAttribute("id")
		ulang = utils.getLang(el)

		iq = Element((None, "iq"))
		iq.attributes["to"] = to
		iq.attributes["from"] = config.jid
		if ID:
			iq.attributes["id"] = ID
		iq.attributes["type"] = "result"

		query = iq.addElement("query")
		query.attributes["xmlns"] = globals.DISCO_ITEMS
		query.attributes["node"] = globals.COMMANDS
		
		rights = rights_guest
		if toj_uh in self.pytrans.sessions: # logined
			rights = rights_user 
		if toj_uh in config.admins: # admin
			rights = rights_admin
			
		for command in self.commands:
			if self.commandRights[command] <= rights: # user can view this item (enough rights)
				item = query.addElement("item")
				item.attributes["jid"] = config.jid
				item.attributes["node"] = command
				item.attributes["name"] = lang.get(self.commandNames[command], ulang)

		self.pytrans.send(iq)
Example #19
0
	def sendError(self, node, el, errormsg, sessionid=None):
		to = el.getAttribute("from")
		ID = el.getAttribute("id")
		ulang = utils.getLang(el)

		iq = Element((None, "iq"))
		iq.attributes["to"] = to
		iq.attributes["from"] = config.jid
		if ID:
			iq.attributes["id"] = ID
		iq.attributes["type"] = "result"

		command = iq.addElement("command")
		if sessionid:
			command.attributes["sessionid"] = sessionid
		else:
			command.attributes["sessionid"] = self.pytrans.makeMessageID()
		command.attributes["node"] = node
		command.attributes["xmlns"] = globals.COMMANDS
		command.attributes["status"] = "completed"

		note = command.addElement("note")
		note.attributes["type"] = "error"
		note.addContent(errormsg)

		self.pytrans.send(iq)
Example #20
0
    def incomingIq(self, el):
        to = el.getAttribute("from")
        ID = el.getAttribute("id")
        ulang = utils.getLang(el)

        iq = Element((None, "iq"))
        iq.attributes["to"] = to
        iq.attributes["from"] = config.jid
        if ID:
            iq.attributes["id"] = ID
        iq.attributes["type"] = "result"

        command = iq.addElement("command")
        command.attributes["sessionid"] = self.pytrans.makeMessageID()
        command.attributes["xmlns"] = globals.COMMANDS
        command.attributes["status"] = "completed"

        x = command.addElement("x")
        x.attributes["xmlns"] = globals.XDATA
        x.attributes["type"] = "result"

        title = x.addElement("title")
        title.addContent(lang.get("command_Statistics", ulang))

        for key in self.stats:
            label = lang.get("statistics_%s" % key, ulang)
            description = lang.get("statistics_%s_Desc" % key, ulang)
            field = x.addElement("field")
            field.attributes["var"] = key
            field.attributes["label"] = label
            field.attributes["type"] = "text-single"
            field.addElement("value").addContent(str(self.stats[key]))
            field.addElement("desc").addContent(description)

        self.pytrans.send(iq)
Example #21
0
	def sendRegistrationFields(self, incoming):
		# Construct a reply with the fields they must fill out
		LogEvent(INFO)
		reply = Element((None, "iq"))
		reply.attributes["from"] = config.jid
		reply.attributes["to"] = incoming.getAttribute("from")
		reply.attributes["id"] = incoming.getAttribute("id")
		reply.attributes["type"] = "result"
		query = reply.addElement("query")
		query.attributes["xmlns"] = globals.IQREGISTER
		instructions = query.addElement("instructions")
		ulang = utils.getLang(incoming)
		instructions.addContent(lang.get("registertext", ulang))
		userEl = query.addElement("username")
		passEl = query.addElement("password")
		
		# Check to see if they're registered
		source = internJID(incoming.getAttribute("from")).userhost()
		result = self.pytrans.xdb.getRegistration(source)
		if result:
			username, password = result
			if username != "local":
				userEl.addContent(username)
				query.addElement("registered")
		
		self.pytrans.send(reply)
Example #22
0
	def incomingIq(self, el):
		to = el.getAttribute("from")
		ID = el.getAttribute("id")
		ulang = utils.getLang(el)

		iq = Element((None, "iq"))
		iq.attributes["to"] = to
		iq.attributes["from"] = config.jid
		if ID:
			iq.attributes["id"] = ID
		iq.attributes["type"] = "result"

		command = iq.addElement("command")
		command.attributes["sessionid"] = self.pytrans.makeMessageID()
		command.attributes["xmlns"] = globals.COMMANDS
		command.attributes["status"] = "completed"

		x = command.addElement("x")
		x.attributes["xmlns"] = globals.XDATA
		x.attributes["type"] = "result"

		title = x.addElement("title")
		title.addContent(lang.get("command_Statistics", ulang))

		for key in self.stats:
			label = lang.get("statistics_%s" % key, ulang)
			description = lang.get("statistics_%s_Desc" % key, ulang)
			field = x.addElement("field")
			field.attributes["var"] = key
			field.attributes["label"] = label
			field.attributes["type"] = "text-single"
			field.addElement("value").addContent(str(self.stats[key]))
			field.addElement("desc").addContent(description)

		self.pytrans.send(iq)
Example #23
0
	def updateRegistration(self, incoming):
		# Grab the username and password
		LogEvent(INFO)
		source = internJID(incoming.getAttribute("from")).userhost()
		ulang = utils.getLang(incoming)
		username = None
		password = None
		
		for queryFind in incoming.elements():
			if(queryFind.name == "query"):
				for child in queryFind.elements():
					try:
						if(child.name == "username"):
							username = child.__str__().lower()
						elif(child.name == "password"):
							password = child.__str__()
						elif(child.name == "remove"):
							# The user wants to unregister the transport! Gasp!
							LogEvent(INFO, msg="Unregistering")
							try:
								self.removeRegInfo(source)
								self.successReply(incoming)
							except:
								self.xdbErrorReply(incoming)
								return
							LogEvent(INFO, msg="Unregistered!")
							return
					except AttributeError, TypeError:
						continue # Ignore any errors, we'll check everything below
Example #24
0
def getMoreInfoChamp(nameChamp):
    try:
        # print(f"Id:{id} ")
        pathRoot = utils.getDdragonPath()
        lang = utils.getLang()
        if pathRoot == None or lang == None:
            print("Something went wrong getting the data.")
            return None

        url = f'{pathRoot}{lang}/champion/{nameChamp}.json'
        print(url)
        res = requests.get(url)
        if res.status_code == 200:
            print("Response Status: Ok")
            info = res.json()
            with open(f"test_{nameChamp}.json", 'w') as f:
                f.write(json.dumps(info))
            # print(info)
            print("Information Saved!")
            print("File: " + f"test_{nameChamp}.json")

        else:
            print(f"Error[{res.status_code}]: {res.text}")
            return None

    except Exception as ex:
        print(f"Exception: {ex}")
        return None
	def showHelpAction(self, el, sessionid=None):
		to = el.getAttribute('from')
		ID = el.getAttribute('id')
		ulang = utils.getLang(el)
		
		iq = Element((None, 'iq'))
		iq.attributes['to'] = to
		iq.attributes['from'] = config.jid
		if ID:
			iq.attributes['id'] = ID
		iq.attributes['type'] = 'result'
		
		command = iq.addElement('command')
		if sessionid:
			command.attributes['sessionid'] = sessionid
		else:
			command.attributes['sessionid'] = self.pytrans.makeMessageID()
		command.attributes['node'] = 'help'
		command.attributes['xmlns'] = globals.COMMANDS
		command.attributes['status'] = 'executing'
		
		actions = command.addElement('actions')
		actions.attributes['execute'] = 'next'
		actions.addElement('next')

		x = command.addElement('x')
		x.attributes['xmlns'] = 'jabber:x:data'
		x.attributes['type'] = 'form'

		title = x.addElement('title')
		title.addContent(lang.get('command_Help'))
		
		instructions = x.addElement('instructions')
		instructions.addContent(lang.get('help_documentation'))
		
		field = x.addElement('field')
		field.attributes['var'] = 'help_action'
		field.attributes['type'] = 'list-single'
		field.attributes['label'] = lang.get('help_action')
		desc = field.addElement('desc')
		desc.addContent(lang.get('help_action_Desc'))
		
		option = field.addElement('option')
		option.attributes['label'] = help_mainroom
		value = option.addElement('value')
		value.addContent(help_mainroom)
		
		if config.supportRoom:
			option = field.addElement('option')
			option.attributes['label'] = config.supportRoom
			value = option.addElement('value')
			value.addContent(config.supportRoom)
			
		stage = x.addElement('field')
		stage.attributes['type'] = 'hidden'
		stage.attributes['var'] = 'stage'
		value = stage.addElement('value')
		value.addContent('2')
		
		self.pytrans.send(iq)
	def incomingIq(self, el):
		to = el.getAttribute("from")
		ID = el.getAttribute("id")
		ulang = utils.getLang(el)

		if config.admins.count(internJID(to).userhost()) == 0:
			self.pytrans.iq.sendIqError(to=to, fro=config.jid, ID=ID, xmlns=globals.COMMANDS, etype="cancel", condition="not-authorized")
			return

		self.sendProbes()

		iq = Element((None, "iq"))
		iq.attributes["to"] = to
		iq.attributes["from"] = config.jid
		if ID:
			iq.attributes["id"] = ID
		iq.attributes["type"] = "result"

		command = iq.addElement("command")
		command.attributes["sessionid"] = self.pytrans.makeMessageID()
		command.attributes["xmlns"] = globals.COMMANDS
		command.attributes["status"] = "completed"

		x = command.addElement("x")
		x.attributes["xmlns"] = globals.XDATA
		x.attributes["type"] = "result"

		title = x.addElement("title")
		title.addContent(lang.get("command_ConnectUsers", ulang))

		field = x.addElement("field")
		field.attributes["type"] = "fixed"
		field.addElement("value").addContent(lang.get("command_Done", ulang))

		self.pytrans.send(iq)
Example #27
0
 def incomingIq(self, el):
     fro = el.getAttribute("from")
     ID = el.getAttribute("id")
     itype = el.getAttribute("type")
     if itype == "get":
         self.sendPrompt(fro, ID, utils.getLang(el))
     elif itype == "set":
         self.sendTranslation(fro, ID, el)
Example #28
0
	def incomingIq(self, el):
		to = el.getAttribute("from")
		fro = el.getAttribute("from")
		froj = internJID(fro)
		ID = el.getAttribute("id")
		if not hasattr(self.pytrans, "legacycon"):
			self.pytrans.iq.sendIqError(to=to, fro=config.jid, ID=ID, xmlns=globals.COMMANDS, etype="cancel", condition="service-unavailable")
		ulang = utils.getLang(el)

		if not self.pytrans.sessions.has_key(froj.userhost()):
			self.pytrans.iq.sendIqError(to=fro, fro=config.jid, ID=ID, xmlns=globals.COMMANDS, etype="cancel", condition="service-unavailable")
			return
		s = self.pytrans.sessions[froj.userhost()]
		if not s.ready:
			self.pytrans.iq.sendIqError(to=fro, fro=config.jid, ID=ID, xmlns=globals.COMMANDS, etype="cancel", condition="service-unavailable")
			return

		iq = Element((None, "iq"))
		iq.attributes["to"] = to
		iq.attributes["from"] = config.jid
		if ID:
			iq.attributes["id"] = ID
		iq.attributes["type"] = "result"

		command = iq.addElement("command")
		command.attributes["sessionid"] = self.pytrans.makeMessageID()
		command.attributes["node"] = "retrieveroster"
		command.attributes["xmlns"] = globals.COMMANDS
		command.attributes["status"] = "completed"

		x = command.addElement("x")
		x.attributes["xmlns"] = globals.XDATA
		x.attributes["type"] = "result"

		title = x.addElement("title")
		title.addContent(lang.get("command_RosterRetrieval", ulang))

		reported = x.addElement("reported")
		reported.addChild(utils.makeDataFormElement(None, "legacyid", "Legacy ID"))
		reported.addChild(utils.makeDataFormElement(None, "nick", "Nickname"))

		entities = s.pytrans.xdb.getList("roster", s.jabberID)
		if entities != None:
			for e in entities:
				name = e[0]
				attrs = e[1]

				item = x.addElement("item")

				field = item.addElement("field")
				field.attributes["var"] = "legacyid"
				field.addElement("value").addContent(name)

				field = item.addElement("field")
				field.attributes["var"] = "nick"
				field.addElement("value").addContent(attrs.get('nickname',''))

		self.pytrans.send(iq)
Example #29
0
	def sendForm(self, el, sessionid=None, errormsg=None):
		to = el.getAttribute("from")
		ID = el.getAttribute("id")
		ulang = utils.getLang(el)

		iq = Element((None, "iq"))
		iq.attributes["to"] = to
		iq.attributes["from"] = config.jid
		if ID:
			iq.attributes["id"] = ID
		iq.attributes["type"] = "result"

		command = iq.addElement("command")
		if sessionid:
			command.attributes["sessionid"] = sessionid
		else:
			command.attributes["sessionid"] = self.pytrans.makeMessageID()
		command.attributes["node"] = "changepassword"
		command.attributes["xmlns"] = globals.COMMANDS
		command.attributes["status"] = "executing"

		if errormsg:
			note = command.addElement("note")
			note.attributes["type"] = "error"
			note.addContent(errormsg)

		actions = command.addElement("actions")
		actions.attributes["execute"] = "complete"
		actions.addElement("complete")

		x = command.addElement("x")
		x.attributes["xmlns"] = "jabber:x:data"
		x.attributes["type"] = "form"

		title = x.addElement("title")
		title.addContent(lang.get("command_ChangePassword", ulang))

		instructions = x.addElement("instructions")
		instructions.addContent(lang.get("command_ChangePassword_Instructions", ulang))

		oldpassword = x.addElement("field")
		oldpassword.attributes["type"] = "text-private"
		oldpassword.attributes["var"] = "oldpassword"
		oldpassword.attributes["label"] = lang.get("command_ChangePassword_OldPassword", ulang)

		newpassword = x.addElement("field")
		newpassword.attributes["type"] = "text-private"
		newpassword.attributes["var"] = "newpassword"
		newpassword.attributes["label"] = lang.get("command_ChangePassword_NewPassword", ulang)

		newpassworda = x.addElement("field")
		newpassworda.attributes["type"] = "text-private"
		newpassworda.attributes["var"] = "newpasswordagain"
		newpassworda.attributes["label"] = lang.get("command_ChangePassword_NewPasswordAgain", ulang)

		self.pytrans.send(iq)
Example #30
0
    def incomingIq(self, el):
        to = el.getAttribute("from")
        toj = internJID(to)
        ID = el.getAttribute("id")
        ulang = utils.getLang(el)

        sessionid = None
        oldpassword = None
        newpassword = None
        newpasswordagain = None

        for command in el.elements():
            sessionid = command.getAttribute("sessionid")
            if command.getAttribute("action") == "cancel":
                self.pytrans.adhoc.sendCancellation("changepassword", el,
                                                    sessionid)
                return
            for child in command.elements():
                if child.name == "x" and child.getAttribute(
                        "type") == "submit":
                    for field in child.elements():
                        if field.name == "field" and field.getAttribute(
                                "var") == "newpassword":
                            for value in field.elements():
                                if value.name == "value":
                                    newpassword = value.__str__()
                        elif field.name == "field" and field.getAttribute(
                                "var") == "newpasswordagain":
                            for value in field.elements():
                                if value.name == "value":
                                    newpasswordagain = value.__str__()
                        elif field.name == "field" and field.getAttribute(
                                "var") == "oldpassword":
                            for value in field.elements():
                                if value.name == "value":
                                    oldpassword = value.__str__()

        if not self.pytrans.sessions.has_key(toj.userhost()) or not hasattr(
                self.pytrans.sessions[toj.userhost()].legacycon, "bos"):
            self.pytrans.adhoc.sendError("changepassword",
                                         el,
                                         errormsg=lang.get(
                                             "command_NoSession", ulang),
                                         sessionid=sessionid)
        elif newpassword and newpassword != newpasswordagain:
            self.sendForm(el,
                          sessionid=sessionid,
                          errormsg=lang.get("command_ChangePassword_Mismatch",
                                            ulang))
        elif oldpassword and newpassword:
            self.changePassword(el, oldpassword, newpassword, sessionid)
        else:
            self.sendForm(el)
Example #31
0
 def onIq(self, el):
     """ Decides what to do with an IQ """
     fro = el.getAttribute("from")
     to = el.getAttribute("to")
     ID = el.getAttribute("id")
     iqType = el.getAttribute("type")
     ulang = utils.getLang(el)
     try:  # StringPrep
         froj = internJID(fro)
         to = internJID(to).full()
     except Exception, e:
         LogEvent(INFO, msg="Dropping IQ because of stringprep error")
Example #32
0
	def incomingIq(self, el):
		""" Decides what to do with an IQ """
		fro = el.getAttribute("from")
		to = el.getAttribute("to")
		ID = el.getAttribute("id")
		iqType = el.getAttribute("type")
		ulang = utils.getLang(el)
		try: # StringPrep
			froj = internJID(fro)
			to = internJID(to).full()
		except Exception, e:
			LogEvent(INFO, msg="Dropping IQ because of stringprep error")
	def incomingIq(self, el):
		to = el.getAttribute("from")
		ID = el.getAttribute("id")
		ulang = utils.getLang(el)

		iq = Element((None, "iq"))
		iq.attributes["to"] = to
		iq.attributes["from"] = config.jid
		if ID:
			iq.attributes["id"] = ID
		iq.attributes["type"] = "result"

		sessionid = None
		refresh = False
		if el.firstChildElement():
			sessionid = el.firstChildElement().getAttribute('sessionid')
			if el.firstChildElement().getAttribute('action') == 'next':
				refresh = True

		command = iq.addElement("command")
		if not refresh and sessionid:
			command.attributes["status"] = 'completed'
		else:
			command.attributes["status"] = 'executing'
			actions = command.addElement('actions')
			actions.attributes['execute'] = 'complete'
			actions.addElement('next')
			actions.addElement('complete')
		if not sessionid:
			sessionid = self.pytrans.makeMessageID()
		command.attributes["sessionid"] = sessionid
		command.attributes["xmlns"] = globals.COMMANDS
		command.attributes['node'] = 'stats'

		x = command.addElement("x")
		x.attributes["xmlns"] = globals.XDATA
		x.attributes["type"] = "result"

		title = x.addElement("title")
		title.addContent(lang.get("command_Statistics", ulang))

		for key in self.stats:
			label = lang.get("statistics_%s" % key, ulang)
			description = lang.get("statistics_%s_Desc" % key, ulang)
			field = x.addElement("field")
			field.attributes["var"] = key
			field.attributes["label"] = label
			field.attributes["type"] = "text-single"
			field.addElement("value").addContent(str(self.stats[key]))
			field.addElement("desc").addContent(description)

		self.pytrans.send(iq)
Example #34
0
    def sendForm(self, current, el, sessionid=None, errormsg=None):
        to = el.getAttribute("from")
        ID = el.getAttribute("id")
        ulang = utils.getLang(el)

        iq = Element((None, "iq"))
        iq.attributes["to"] = to
        iq.attributes["from"] = config.jid
        if ID:
            iq.attributes["id"] = ID
        iq.attributes["type"] = "result"

        command = iq.addElement("command")
        if sessionid:
            command.attributes["sessionid"] = sessionid
        else:
            command.attributes["sessionid"] = self.pytrans.makeMessageID()
        command.attributes["node"] = "formatscreenname"
        command.attributes["xmlns"] = globals.COMMANDS
        command.attributes["status"] = "executing"

        if errormsg:
            note = command.addElement("note")
            note.attributes["type"] = "error"
            note.addContent(errormsg)

        actions = command.addElement("actions")
        actions.attributes["execute"] = "complete"
        actions.addElement("complete")

        x = command.addElement("x")
        x.attributes["xmlns"] = globals.XDATA
        x.attributes["type"] = "form"

        title = x.addElement("title")
        title.addContent(lang.get("command_FormatScreenName", ulang))

        instructions = x.addElement("instructions")
        instructions.addContent(
            lang.get("command_FormatScreenName_Instructions", ulang))

        fmtsn = x.addElement("field")
        fmtsn.attributes["type"] = "text-single"
        fmtsn.attributes["var"] = "fmtsn"
        fmtsn.attributes["label"] = lang.get(
            "command_FormatScreenName_FMTScreenName", ulang)
        if current[1]:
            fmtsn.addElement("value").addContent(current[1])

        self.pytrans.send(iq)
Example #35
0
	def processSearch(self, el):
		LogEvent(INFO)
		ulang = utils.getLang(el)
		iq = Element((None, "iq"))
		iq.attributes["type"] = "result"
		to = el.getAttribute("to")
		iq.attributes["from"] = to
		fro = el.getAttribute("from")
		iq.attributes["to"] = fro
		ID = el.getAttribute("id")
		if ID:
			iq.attributes["id"] = ID
		query = iq.addElement("query")
		query.attributes["xmlns"] = globals.IQSEARCH
		x = query.addElement("x")
		x.attributes["xmlns"] = globals.XDATA
		x.attributes["type"] = "result"
		x.addChild(utils.makeDataFormElement("hidden", "FORM_TYPE", value="jabber:iq:search"))
		reported = x.addElement("reported")
		reported.addChild(utils.makeDataFormElement(None, "jid", "Jabber ID"))
		reported.addChild(utils.makeDataFormElement(None, "first", "First Name"))
		reported.addChild(utils.makeDataFormElement(None, "middle", "Middle Name"))
		reported.addChild(utils.makeDataFormElement(None, "last", "Last Name"))
		reported.addChild(utils.makeDataFormElement(None, "maiden", "Maiden Name"))
		reported.addChild(utils.makeDataFormElement(None, "nick", "Nickname"))
		reported.addChild(utils.makeDataFormElement(None, "email", "E-Mail Address"))
		reported.addChild(utils.makeDataFormElement(None, "address", "Street Address"))
		reported.addChild(utils.makeDataFormElement(None, "city", "City"))
		reported.addChild(utils.makeDataFormElement(None, "state", "State"))
		reported.addChild(utils.makeDataFormElement(None, "country", "Country"))
		reported.addChild(utils.makeDataFormElement(None, "zip", "Zip Code"))
		reported.addChild(utils.makeDataFormElement(None, "region", "Region"))

		dataform = None
		for query in el.elements():
			if query.name == "query":
				for child in query.elements():
					if child.name == "x":
						dataform = child
						break
				break

		if not hasattr(self.pytrans, "legacycon"):
			self.pytrans.iq.sendIqError(to=to, fro=config.jid, ID=ID, xmlns=globals.IQSEARCH, etype="cancel", condition="bad-request")

		if dataform:
			self.pytrans.legacycon.doSearch(dataform, iq).addCallback(self.gotSearchResponse)
		else:
			self.pytrans.iq.sendIqError(to=to, fro=config.jid, ID=ID, xmlns=globals.IQSEARCH, etype="retry", condition="bad-request")
Example #36
0
    def sendForm(self, el, sessionid=None, errormsg=None):
        to = el.getAttribute("from")
        ID = el.getAttribute("id")
        ulang = utils.getLang(el)

        iq = Element((None, "iq"))
        iq.attributes["to"] = to
        iq.attributes["from"] = config.jid
        if ID:
            iq.attributes["id"] = ID
        iq.attributes["type"] = "result"

        command = iq.addElement("command")
        if sessionid:
            command.attributes["sessionid"] = sessionid
        else:
            command.attributes["sessionid"] = self.pytrans.makeMessageID()
        command.attributes["node"] = "emaillookup"
        command.attributes["xmlns"] = globals.COMMANDS
        command.attributes["status"] = "executing"

        if errormsg:
            note = command.addElement("note")
            note.attributes["type"] = "error"
            note.addContent(errormsg)

        actions = command.addElement("actions")
        actions.attributes["execute"] = "complete"
        actions.addElement("complete")

        x = command.addElement("x")
        x.attributes["xmlns"] = "jabber:x:data"
        x.attributes["type"] = "form"

        title = x.addElement("title")
        title.addContent(lang.get("command_EmailLookup", ulang))

        instructions = x.addElement("instructions")
        instructions.addContent(
            lang.get("command_EmailLookup_Instructions", ulang))

        email = x.addElement("field")
        email.attributes["type"] = "text-single"
        email.attributes["var"] = "email"
        email.attributes["label"] = lang.get("command_EmailLookup_Email",
                                             ulang)

        self.pytrans.send(iq)
Example #37
0
	def sendForm(self, current, el, sessionid=None, errormsg=None):
		to = el.getAttribute("from")
		ID = el.getAttribute("id")
		ulang = utils.getLang(el)

		iq = Element((None, "iq"))
		iq.attributes["to"] = to
		iq.attributes["from"] = config.jid
		if ID:
			iq.attributes["id"] = ID
		iq.attributes["type"] = "result"

		command = iq.addElement("command")
		if sessionid:
			command.attributes["sessionid"] = sessionid
		else:
			command.attributes["sessionid"] = self.pytrans.makeMessageID()
		command.attributes["node"] = "changeemail"
		command.attributes["xmlns"] = globals.COMMANDS
		command.attributes["status"] = "executing"

		if errormsg:
			note = command.addElement("note")
			note.attributes["type"] = "error"
			note.addContent(errormsg)

		actions = command.addElement("actions")
		actions.attributes["execute"] = "complete"
		actions.addElement("complete")

		x = command.addElement("x")
		x.attributes["xmlns"] = "jabber:x:data"
		x.attributes["type"] = "form"

		title = x.addElement("title")
		title.addContent(lang.get("command_ChangeEmail", ulang))

		instructions = x.addElement("instructions")
		instructions.addContent(lang.get("command_ChangeEmail_Instructions", ulang))

		email = x.addElement("field")
		email.attributes["type"] = "text-single"
		email.attributes["var"] = "email"
		email.attributes["label"] = lang.get("command_ChangeEmail_Email", ulang)
		if current[4]:
			email.addElement("value").addContent(current[4])

		self.pytrans.send(iq)
Example #38
0
	def sendForm(self, current, el, sessionid=None, errormsg=None):
		to = el.getAttribute("from")
		ID = el.getAttribute("id")
		ulang = utils.getLang(el)

		iq = Element((None, "iq"))
		iq.attributes["to"] = to
		iq.attributes["from"] = config.jid
		if ID:
			iq.attributes["id"] = ID
		iq.attributes["type"] = "result"

		command = iq.addElement("command")
		if sessionid:
			command.attributes["sessionid"] = sessionid
		else:
			command.attributes["sessionid"] = self.pytrans.makeMessageID()
		command.attributes["node"] = "formatscreenname"
		command.attributes["xmlns"] = globals.COMMANDS
		command.attributes["status"] = "executing"

		if errormsg:
			note = command.addElement("note")
			note.attributes["type"] = "error"
			note.addContent(errormsg)

		actions = command.addElement("actions")
		actions.attributes["execute"] = "complete"
		actions.addElement("complete")

		x = command.addElement("x")
		x.attributes["xmlns"] = globals.XDATA
		x.attributes["type"] = "form"

		title = x.addElement("title")
		title.addContent(lang.get("command_FormatScreenName", ulang))

		instructions = x.addElement("instructions")
		instructions.addContent(lang.get("command_FormatScreenName_Instructions", ulang))

		fmtsn = x.addElement("field")
		fmtsn.attributes["type"] = "text-single"
		fmtsn.attributes["var"] = "fmtsn"
		fmtsn.attributes["label"] = lang.get("command_FormatScreenName_FMTScreenName", ulang)
		if current[1]:
			fmtsn.addElement("value").addContent(current[1])

		self.pytrans.send(iq)
	def sendInvitation(self, el, help_action, sessionid=None):
		to = el.getAttribute('from')
		ID = el.getAttribute('id')
		ulang = utils.getLang(el)
		
		message = Element((None, 'message'))
		message.attributes['to'] = to
		message.attributes['from'] = config.jid
		if ID:
			message.attributes['id'] = ID
			
		x = message.addElement('x')
		x.attributes['xmlns'] = 'jabber:x:conference'
		x.attributes['jid'] = help_action
		
		self.pytrans.send(message)
Example #40
0
	def sendForm(self, el, sessionid=None, errormsg=None):
		to = el.getAttribute("from")
		ID = el.getAttribute("id")
		ulang = utils.getLang(el)

		iq = Element((None, "iq"))
		iq.attributes["to"] = to
		iq.attributes["from"] = config.jid
		if ID:
			iq.attributes["id"] = ID
		iq.attributes["type"] = "result"

		command = iq.addElement("command")
		if sessionid:
			command.attributes["sessionid"] = sessionid
		else:
			command.attributes["sessionid"] = self.pytrans.makeMessageID()
		command.attributes["node"] = "aimuritranslate"
		command.attributes["xmlns"] = globals.COMMANDS
		command.attributes["status"] = "executing"

		if errormsg:
			note = command.addElement("note")
			note.attributes["type"] = "error"
			note.addContent(errormsg)

		actions = command.addElement("actions")
		actions.attributes["execute"] = "complete"
		actions.addElement("complete")

		x = command.addElement("x")
		x.attributes["xmlns"] = globals.XDATA
		x.attributes["type"] = "form"

		title = x.addElement("title")
		title.addContent(lang.get("command_AIMURITranslate", ulang))

		instructions = x.addElement("instructions")
		instructions.addContent(lang.get("command_AIMURITranslate_Instructions", ulang))

		email = x.addElement("field")
		email.attributes["type"] = "text-single"
		email.attributes["var"] = "uri"
		email.attributes["label"] = lang.get("command_AIMURITranslate_URI", ulang)

		self.pytrans.send(iq)
Example #41
0
	def validateLocalRegistration(self, incoming):
		# Grab the username and password
		LogEvent(INFO)
		source = internJID(incoming.getAttribute("from")).userhost()
		ulang = utils.getLang(incoming)
		username = None
		password = None
                
		for queryFind in incoming.elements():
			if queryFind.name == "query":
				for child in queryFind.elements():
					try:
						if child.name == "username":
							username = child.__str__().lower()
						elif child.name == "password":
							password = child.__str__()
					except AttributeError, TypeError:
						continue # Ignore any errors, we'll check everything below
Example #42
0
	def incomingIq(self, el):
		to = el.getAttribute("from")
		toj = internJID(to)
		ID = el.getAttribute("id")
		ulang = utils.getLang(el)

		sessionid = None

		for command in el.elements():
			sessionid = command.getAttribute("sessionid")
			if command.getAttribute("action") == "cancel":
				self.pytrans.adhoc.sendCancellation("confirmaccount", el, sessionid)
				return

		if not self.pytrans.sessions.has_key(toj.userhost()) or not hasattr(self.pytrans.sessions[toj.userhost()].legacycon, "bos"):
			self.pytrans.adhoc.sendError("confirmaccount", el, errormsg=lang.get("command_NoSession", ulang), sessionid=sessionid)
		else:
			self.pytrans.sessions[toj.userhost()].legacycon.bos.confirmAccount().addCallback(self.sendResponse, el, sessionid)
Example #43
0
	def sendLocalRegistrationFields(self, incoming):
		# Construct a reply with the fields they must fill out
		LogEvent(INFO)
		reply = Element((None, "iq"))
		reply.attributes["from"] = config.jid
		reply.attributes["to"] = incoming.getAttribute("from")
		reply.attributes["id"] = incoming.getAttribute("id")
		reply.attributes["type"] = "result"
		reply.attributes["authenticate"] = "true"
		query = reply.addElement("query")
		query.attributes["xmlns"] = globals.IQREGISTER
		instructions = query.addElement("instructions")
		ulang = utils.getLang(incoming)
		instructions.addContent(lang.get("authenticatetext", ulang))
		userEl = query.addElement("username")
		passEl = query.addElement("password")
                
		self.pytrans.send(reply)
Example #44
0
    def validateLocalRegistration(self, incoming):
        # Grab the username and password
        LogEvent(INFO)
        source = internJID(incoming.getAttribute("from")).userhost()
        ulang = utils.getLang(incoming)
        username = None
        password = None

        for queryFind in incoming.elements():
            if queryFind.name == "query":
                for child in queryFind.elements():
                    try:
                        if child.name == "username":
                            username = child.__str__().lower()
                        elif child.name == "password":
                            password = child.__str__()
                    except AttributeError, TypeError:
                        continue  # Ignore any errors, we'll check everything below
Example #45
0
    def sendLocalRegistrationFields(self, incoming):
        # Construct a reply with the fields they must fill out
        LogEvent(INFO)
        reply = Element((None, "iq"))
        reply.attributes["from"] = config.jid
        reply.attributes["to"] = incoming.getAttribute("from")
        reply.attributes["id"] = incoming.getAttribute("id")
        reply.attributes["type"] = "result"
        reply.attributes["authenticate"] = "true"
        query = reply.addElement("query")
        query.attributes["xmlns"] = globals.IQREGISTER
        instructions = query.addElement("instructions")
        ulang = utils.getLang(incoming)
        instructions.addContent(lang.get("authenticatetext", ulang))
        userEl = query.addElement("username")
        passEl = query.addElement("password")

        self.pytrans.send(reply)
	def emailLookupResults(self, results, el, sessionid):
		LogEvent(INFO)
		to = el.getAttribute("from")
		toj = internJID(to)
		ID = el.getAttribute("id")
		ulang = utils.getLang(el)

		iq = Element((None, "iq"))
		iq.attributes["to"] = to
		iq.attributes["from"] = config.jid
		if ID:
			iq.attributes["id"] = ID
		iq.attributes["type"] = "result"

		command = iq.addElement("command")
		if sessionid:
			command.attributes["sessionid"] = sessionid
		else:
			command.attributes["sessionid"] = self.pytrans.makeMessageID()
		command.attributes["node"] = "emaillookup"
		command.attributes["xmlns"] = globals.COMMANDS
		command.attributes["status"] = "completed"

		x = command.addElement("x")
		x.attributes["xmlns"] = "jabber:x:data"
		x.attributes["type"] = "form"

		title = x.addElement("title")
		title.addContent(lang.get("command_EmailLookup", ulang))

		if len(results):
			note = command.addElement("note")
			note.attributes["type"] = "info"
			note.addContent(lang.get("command_EmailLookup_Results", ulang))
			for r in results:
				email = x.addElement("field")
				email.attributes["type"] = "fixed"
				email.addElement("value").addContent(r)
		else:
			note = command.addElement("note")
			note.attributes["type"] = "info"
			note.addContent(lang.get("command_EmailLookup_NoResults", ulang))

		self.pytrans.send(iq)
Example #47
0
	def getMyVCard(self, el):
		to = el.getAttribute("from")
		fro = el.getAttribute("from")
		froj = internJID(fro)
		ID = el.getAttribute("id")
		ulang = utils.getLang(el)

		if not self.pytrans.sessions.has_key(froj.userhost()):
			self.pytrans.iq.sendIqError(to=fro, fro=config.jid, ID=ID, xmlns="vcard-temp", etype="auth", condition="not-authorized")
			return
		s = self.pytrans.sessions[froj.userhost()]
		if not s.ready:
			self.pytrans.iq.sendIqError(to=fro, fro=config.jid, ID=ID, xmlns="vcard-temp", etype="auth", condition="not-authorized")
			return

		s.doVCardUpdate()

		iq = Element((None, "iq"))
		iq.attributes["to"] = to
		iq.attributes["from"] = config.jid
		if ID:
			iq.attributes["id"] = ID
		iq.attributes["type"] = "result"

		command = iq.addElement("command")
		command.attributes["sessionid"] = self.pytrans.makeMessageID()
		command.attributes["xmlns"] = globals.COMMANDS
		command.attributes["status"] = "completed"

		x = command.addElement("x")
		x.attributes["xmlns"] = globals.XDATA
		x.attributes["type"] = "result"

		title = x.addElement("title")
		title.addContent(lang.get("command_UpdateMyVCard", ulang))

		field = x.addElement("field")
		field.attributes["type"] = "fixed"
		field.addElement("value").addContent(lang.get("command_Done", ulang))

		self.pytrans.send(iq)
	def getMyVCard(self, el):
		to = el.getAttribute("from")
		fro = el.getAttribute("from")
		froj = internJID(fro)
		ID = el.getAttribute("id")
		ulang = utils.getLang(el)

		if not self.pytrans.sessions.has_key(froj.userhost()):
			self.pytrans.iq.sendIqError(to=fro, fro=config.jid, ID=ID, xmlns="vcard-temp", etype="auth", condition="not-authorized")
			return
		s = self.pytrans.sessions[froj.userhost()]
		if not s.ready:
			self.pytrans.iq.sendIqError(to=fro, fro=config.jid, ID=ID, xmlns="vcard-temp", etype="auth", condition="not-authorized")
			return

		s.doVCardUpdate()

		iq = Element((None, "iq"))
		iq.attributes["to"] = to
		iq.attributes["from"] = config.jid
		if ID:
			iq.attributes["id"] = ID
		iq.attributes["type"] = "result"

		command = iq.addElement("command")
		command.attributes["sessionid"] = self.pytrans.makeMessageID()
		command.attributes["xmlns"] = globals.COMMANDS
		command.attributes["status"] = "completed"

		x = command.addElement("x")
		x.attributes["xmlns"] = globals.XDATA
		x.attributes["type"] = "result"

		title = x.addElement("title")
		title.addContent(lang.get("command_UpdateMyVCard", ulang))

		field = x.addElement("field")
		field.attributes["type"] = "fixed"
		field.addElement("value").addContent(lang.get("command_Done", ulang))

		self.pytrans.send(iq)
	def incomingIq(self, el):
		to = el.getAttribute('from')
		toj = internJID(to)
		ID = el.getAttribute('id')
		ulang = utils.getLang(el)

		sessionid = None
		help_action = None
		action = None
		stage = '0'

		for command in el.elements():
			sessionid = command.getAttribute('sessionid')
			action = command.getAttribute('action')
			if action == 'cancel':
				self.pytrans.adhoc.sendCancellation('help', el, sessionid)
				return
			for child in command.elements():
				if child.name == 'x':
					for field in child.elements():
						if field.name == 'field':
							if field.getAttribute('var') == 'help_action':
								for value in field.elements():
									if value.name == 'value':
										help_action = value.__str__()
							elif field.getAttribute('var') == 'stage':
								for value in field.elements():
									if value.name == 'value':
										stage = value.__str__()
		if str(stage) == '0':
			self.showHelp(el, sessionid)
		elif str(stage) == '1':
			if not action or action == 'next':
				self.showHelpAction(el, sessionid)
			else:
				self.showHelpDone(el, lang.get('command_Done'), sessionid)
		elif str(stage) == '2':
			self.showHelpDone(el, lang.get('help_invitation_sent'), sessionid)
			if help_action:
				self.sendInvitation(el, help_action, sessionid)
Example #50
0
    def emailLookupResults(self, results, el, sessionid):
        LogEvent(INFO)
        to = el.getAttribute("from")
        toj = internJID(to)
        ID = el.getAttribute("id")
        ulang = utils.getLang(el)

        iq = Element((None, "iq"))
        iq.attributes["to"] = to
        iq.attributes["from"] = config.jid
        if ID:
            iq.attributes["id"] = ID
        iq.attributes["type"] = "result"

        command = iq.addElement("command")
        if sessionid:
            command.attributes["sessionid"] = sessionid
        else:
            command.attributes["sessionid"] = self.pytrans.makeMessageID()
        command.attributes["node"] = "emaillookup"
        command.attributes["xmlns"] = globals.COMMANDS
        command.attributes["status"] = "completed"

        note = command.addElement("note")
        note.attributes["type"] = "info"
        note.addContent(lang.get("command_EmailLookup_Results", ulang))

        x = command.addElement("x")
        x.attributes["xmlns"] = "jabber:x:data"
        x.attributes["type"] = "form"

        title = x.addElement("title")
        title.addContent(lang.get("command_EmailLookup", ulang))

        for r in results:
            email = x.addElement("field")
            email.attributes["type"] = "fixed"
            email.addElement("value").addContent(r)

        self.pytrans.send(iq)
Example #51
0
    def incomingIq(self, el):
        to = el.getAttribute("from")
        ID = el.getAttribute("id")
        ulang = utils.getLang(el)

        if config.admins.count(internJID(to).userhost()) == 0:
            self.pytrans.discovery.sendIqError(to=to,
                                               fro=config.jid,
                                               ID=ID,
                                               xmlns=disco.COMMANDS,
                                               etype="cancel",
                                               condition="not-authorized")
            return

        self.sendProbes()

        iq = Element((None, "iq"))
        iq.attributes["to"] = to
        iq.attributes["from"] = config.jid
        if (ID):
            iq.attributes["id"] = ID
        iq.attributes["type"] = "result"

        command = iq.addElement("command")
        command.attributes["sessionid"] = self.pytrans.makeMessageID()
        command.attributes["xmlns"] = disco.COMMANDS
        command.attributes["status"] = "completed"

        x = command.addElement("x")
        x.attributes["xmlns"] = disco.XDATA
        x.attributes["type"] = "result"

        title = x.addElement("title")
        title.addContent(lang.get(ulang).command_ConnectUsers)

        field = x.addElement("field")
        field.attributes["type"] = "fixed"
        field.addElement("value").addContent(lang.get(ulang).command_Done)

        self.pytrans.send(iq)
Example #52
0
	def sendCancellation(self, node, el, sessionid=None):
		to = el.getAttribute("from")
		ID = el.getAttribute("id")
		ulang = utils.getLang(el)

		iq = Element((None, "iq"))
		iq.attributes["to"] = to
		iq.attributes["from"] = config.jid
		if ID:
			iq.attributes["id"] = ID
		iq.attributes["type"] = "result"

		command = iq.addElement("command")
		if sessionid:
			command.attributes["sessionid"] = sessionid
		else:
			command.attributes["sessionid"] = self.pytrans.makeMessageID()
		command.attributes["node"] = node
		command.attributes["xmlns"] = globals.COMMANDS
		command.attributes["status"] = "canceled"

		self.pytrans.send(iq)
Example #53
0
def getChampFromddragonJson(id):
    try:
        pathRoot = utils.getDdragonPath()
        lang = utils.getLang()
        if pathRoot == None or lang == None:
            print("Something went wrong getting the data.")
            return None

        url = f'{pathRoot}{lang}/champion.json'
        res = requests.get(url)
        if res.status_code == 200:
            print("Response Status: Ok")
            listChampions = res.json()
            print(
                f"Resume: {listChampions['type']}, {listChampions['version']}")
            data = listChampions['data']
            print(f"{len(data)} number of champions returned")
            nameChamp = ''
            for name, datas in data.items(
            ):  # for name, age in dictionary.iteritems():  (for Python 2.x)
                if datas['key'] == id:
                    nameChamp = name
            if len(nameChamp.strip()) > 0:
                # print(f"Champ found: {nameChamp}")
                # print(f"{nameChamp}'s info:")
                # print(data[nameChamp])
                return data[nameChamp]
            else:
                print(f"Champ not found.")
                return None
        else:
            print("Something went wrong!")
            print(f"Error[{res.status_code}]: {res.text}")
            return None

    except Exception as ex:
        print(f"Exception: {ex}")
        return None
Example #54
0
	def sendCommandList(self, el):
		to = el.getAttribute("from")
		ID = el.getAttribute("id")
		ulang = utils.getLang(el)

		iq = Element((None, "iq"))
		iq.attributes["to"] = to
		iq.attributes["from"] = config.jid
		if ID:
			iq.attributes["id"] = ID
		iq.attributes["type"] = "result"

		query = iq.addElement("query")
		query.attributes["xmlns"] = globals.DISCO_ITEMS
		query.attributes["node"] = globals.COMMANDS

		for command in self.commands:
			item = query.addElement("item")
			item.attributes["jid"] = config.jid
			item.attributes["node"] = command
			item.attributes["name"] = lang.get(self.commandNames[command], ulang)

		self.pytrans.send(iq)
Example #55
0
    def incomingIq(self, el):
        to = el.getAttribute("from")
        toj = internJID(to)
        ID = el.getAttribute("id")
        ulang = utils.getLang(el)

        sessionid = None
        uri = None

        for command in el.elements():
            sessionid = command.getAttribute("sessionid")
            if command.getAttribute("action") == "cancel":
                self.pytrans.adhoc.sendCancellation("aimuritranslate", el,
                                                    sessionid)
                return
            for child in command.elements():
                if child.name == "x" and child.getAttribute(
                        "type") == "submit":
                    for field in child.elements():
                        if field.name == "field" and field.getAttribute(
                                "var") == "uri":
                            for value in field.elements():
                                if value.name == "value":
                                    uri = value.__str__()

        if not self.pytrans.sessions.has_key(toj.userhost()) or not hasattr(
                self.pytrans.sessions[toj.userhost()].legacycon, "bos"):
            self.pytrans.adhoc.sendError("aimuritranslate",
                                         el,
                                         errormsg=lang.get(
                                             "command_NoSession", ulang),
                                         sessionid=sessionid)
        elif uri:
            self.translateUri(el, uri, sessionid=sessionid)
        else:
            self.sendForm(el)
Example #56
0
    def streamEnd(self, errelem):
        LogEvent(INFO)

    def onMessage(self, el):
        fro = el.getAttribute("from")
        to = el.getAttribute("to")
        mtype = el.getAttribute("type")
        try:
            froj = internJID(fro)
        except Exception, e:
            LogEvent(WARN, msg="Failed stringprep")
            return
        if self.sessions.has_key(froj.userhost()):
            self.sessions[froj.userhost()].onMessage(el)
        elif mtype != "error":
            ulang = utils.getLang(el)
            body = None
            for child in el.elements():
                if child.name == "body":
                    body = child.__str__()
            LogEvent(
                INFO,
                msg="Sending error response to a message outside of seession")
            jabw.sendErrorMessage(self, fro, to, "auth", "not-authorized",
                                  lang.get("notloggedin", ulang), body)

    def onPresence(self, el):
        fro = el.getAttribute("from")
        to = el.getAttribute("to")
        # Ignore any presence broadcasts about other JD2 components
        if to == None: return