From 4fb271ad1fd30ede8c3e0a86cc4b9328cb2da170 Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Tue, 4 Nov 2003 12:14:40 +0000 Subject: [PATCH] ask authorization when a user request it --- core/core.py | 9 ++++++++- doc/gajimrc | 1 + plugins/gtkgui.glade | 3 +++ plugins/gtkgui.py | 33 ++++++++++++++++++++++++++++----- 4 files changed, 40 insertions(+), 6 deletions(-) diff --git a/core/core.py b/core/core.py index 1b4f43d6f..6dcaf758d 100644 --- a/core/core.py +++ b/core/core.py @@ -64,7 +64,10 @@ class GajimCore: (prs.getFrom().getBasic(), 'offline', prs.getStatus())) elif type == 'subscribe': log.debug("subscribe request from %s" % who) - self.con.send(common.jabber.Presence(who, 'subscribed')) + if self.cfgParser.Core_alwaysauth == 1: + self.con.send(common.jabber.Presence(who, 'subscribed')) + else: + self.hub.sendPlugin('SUBSCRIBE', who) elif type == 'subscribed': #plein de trucs a faire jid = prs.getFrom() @@ -145,6 +148,9 @@ class GajimCore: #('REQ', jid) elif ev[0] == 'AUTH': self.con.send(common.jabber.Presence(ev[1], 'subscribed')) + #('DENY', jid) + elif ev[0] == 'DENY': + self.con.send(common.jabber.Presence(ev[1], 'unsubscribed')) #('UNSUB', jid) elif ev[0] == 'UNSUB': delauth = self.cfgParser.Core_delauth @@ -173,5 +179,6 @@ def start(): gc.hub.register('gtkgui', 'NOTIFY') gc.hub.register('gtkgui', 'MSG') gc.hub.register('gtkgui', 'SUBSCRIBED') + gc.hub.register('gtkgui', 'SUBSCRIBE') guiPl.load () gc.mainLoop() diff --git a/doc/gajimrc b/doc/gajimrc index 30651130d..3099c01a9 100644 --- a/doc/gajimrc +++ b/doc/gajimrc @@ -12,6 +12,7 @@ ressource = gajim delauth = 1 delroster = 1 +alwaysauth = 0 [GtkGui] diff --git a/plugins/gtkgui.glade b/plugins/gtkgui.glade index b09f7f8fa..a1e954529 100644 --- a/plugins/gtkgui.glade +++ b/plugins/gtkgui.glade @@ -1684,6 +1684,7 @@ David Ferlier (david@yazzy.org) True True GTK_RELIEF_NORMAL + @@ -1749,6 +1750,7 @@ David Ferlier (david@yazzy.org) True True GTK_RELIEF_NORMAL + @@ -1814,6 +1816,7 @@ David Ferlier (david@yazzy.org) True True GTK_RELIEF_NORMAL + diff --git a/plugins/gtkgui.py b/plugins/gtkgui.py index 69cbd12de..b43e72fda 100644 --- a/plugins/gtkgui.py +++ b/plugins/gtkgui.py @@ -52,8 +52,6 @@ class user: # self.status = args[0].status # self.sub = args[0].sub else: raise TypeError, 'bad arguments' -# self.jid = self.name + '@' + self.server + '/' + self.resource -# self.jid = self.name + '@' + self.server class add: def delete_event(self, widget): @@ -68,9 +66,11 @@ class add: self.r.req_sub(self, who, txt) self.delete_event(self) - def __init__(self, roster): + def __init__(self, roster, jid=None): self.r = roster self.xml = gtk.glade.XML('plugins/gtkgui.glade', 'Add') + if jid: + self.xml.get_widget('entry_who').set_text(jid) self.Wadd = self.xml.get_widget("Add") self.xml.signal_connect('gtk_widget_destroy', self.delete_event) self.xml.signal_connect('on_button_sub_clicked', self.on_subscribe) @@ -112,6 +112,29 @@ class confirm: self.xml.signal_connect('on_okbutton_clicked', self.req_usub) self.xml.signal_connect('gtk_widget_destroy', self.delete_event) +class authorize: + def delete_event(self, widget): + self.window.destroy() + + def auth(self, widget): + self.r.queueOUT.put(('AUTH', self.jid)) + self.delete_event(self) + add(self.r, self.jid) + + def deny(self, widget): + self.r.queueOUT.put(('DENY', self.jid)) + self.delete_event(self) + + def __init__(self, roster, jid): + self.xml = gtk.glade.XML('plugins/gtkgui.glade', 'Sub_req') + self.window = self.xml.get_widget('Sub_req') + self.r = roster + self.jid = jid + self.xml.get_widget('label').set_text('Subscription request from ' + self.jid) + self.xml.signal_connect('on_button_auth_clicked', self.auth) + self.xml.signal_connect('on_button_deny_clicked', self.deny) + self.xml.signal_connect('on_button_close_clicked', self.delete_event) + class message: def delete_event(self, widget): del self.roster.tab_messages[self.user.jid] @@ -288,9 +311,7 @@ class roster: def req_sub(self, widget, jid, txt): self.queueOUT.put(('SUB', (jid, txt))) if not self.l_contact.has_key(jid): - #TODO: sub user1 = user(jid, jid, ['general'], 'requested', 'requested', 'sub') - #TODO: ajouter un grp si necessaire if not self.l_group.has_key('general'): iterG = self.treestore.append(None, (None, 'general', 'group')) self.l_group['general'] = iterG @@ -424,6 +445,8 @@ class plugin: #FIXME:message d'un inconne self.r.tab_messages[ev[1][0]] = message(self.r.l_contact[ev[1][0]]['user'], self.r) self.r.tab_messages[ev[1][0]].print_conversation(ev[1][1]) + elif ev[0] == 'SUBSCRIBE': + authorize(self.r, ev[1]) elif ev[0] == 'SUBSCRIBED': u = self.r.l_contact[ev[1]['jid']]['user'] u.name = ev[1]['nom']