diff --git a/sat_frontends/jp/cmd_file.py b/sat_frontends/jp/cmd_file.py index c27fbb32..5a017e94 100644 --- a/sat_frontends/jp/cmd_file.py +++ b/sat_frontends/jp/cmd_file.py @@ -296,6 +296,7 @@ class Receive(base.CommandAnswering): self.action_callbacks = { C.META_TYPE_FILE: self.onFileAction, C.META_TYPE_OVERWRITE: self.onOverwriteAction, + C.META_TYPE_NOT_IN_ROSTER_LEAK: self.onNotInRosterAction, } def add_parser_options(self): @@ -404,6 +405,35 @@ class Receive(base.CommandAnswering): xmlui_data = {"answer": C.boolConst(self.args.force)} await self.host.bridge.launchAction(xmlui_id, xmlui_data, profile_key=profile) + async def onNotInRosterAction(self, action_data, action_id, security_limit, profile): + xmlui_id = self.getXmluiId(action_data) + if xmlui_id is None: + return self.host.quitFromSignal(1) + try: + from_jid = jid.JID(action_data["meta_from_jid"]) + except ValueError: + self.disp(_('invalid "from_jid" value received, ignoring: {value}').format( + value=from_jid), error=True) + return + except KeyError: + self.disp(_('ignoring action without "from_jid" value'), error=True) + return + self.disp(_("Confirmation needed for request from an entity not in roster"), 1) + + if from_jid.bare in self.bare_jids: + # if the sender is expected, we can confirm the session + confirmed = True + self.disp(_("Sender confirmed because she or he is explicitly expected"), 1) + else: + xmlui = xmlui_manager.create(self.host, action_data["xmlui"]) + confirmed = await self.host.confirm(xmlui.dlg.message) + + xmlui_data = {"answer": C.boolConst(confirmed)} + await self.host.bridge.launchAction(xmlui_id, xmlui_data, profile_key=profile) + if not confirmed and not self.args.multiple: + self.disp(_("Session refused for {from_jid}").format(from_jid=from_jid)) + self.host.quitFromSignal(0) + async def start(self): self.bare_jids = [jid.JID(jid_).bare for jid_ in self.args.jids] self.path = os.path.abspath(self.args.path)