Fix security labels
This commit is contained in:
parent
2cf0fb2eef
commit
e292b78a5d
|
@ -205,7 +205,7 @@ class ChatControl(ChatControlBase):
|
||||||
session = app.connections[self.account].find_controlless_session(
|
session = app.connections[self.account].find_controlless_session(
|
||||||
self.contact.jid, resource)
|
self.contact.jid, resource)
|
||||||
|
|
||||||
self.setup_seclabel(self.xml.get_object('label_selector'))
|
self.setup_seclabel()
|
||||||
if session:
|
if session:
|
||||||
session.control = self
|
session.control = self
|
||||||
self.session = session
|
self.session = session
|
||||||
|
|
|
@ -27,6 +27,7 @@ import os
|
||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
import nbxmpp
|
||||||
from gi.repository import Gtk
|
from gi.repository import Gtk
|
||||||
from gi.repository import Gdk
|
from gi.repository import Gdk
|
||||||
from gi.repository import GLib
|
from gi.repository import GLib
|
||||||
|
@ -167,8 +168,7 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
|
||||||
def status_url_clicked(self, widget, url):
|
def status_url_clicked(self, widget, url):
|
||||||
helpers.launch_browser_mailer('url', url)
|
helpers.launch_browser_mailer('url', url)
|
||||||
|
|
||||||
def setup_seclabel(self, combo):
|
def setup_seclabel(self):
|
||||||
self.seclabel_combo = combo
|
|
||||||
self.seclabel_combo.hide()
|
self.seclabel_combo.hide()
|
||||||
self.seclabel_combo.set_no_show_all(True)
|
self.seclabel_combo.set_no_show_all(True)
|
||||||
lb = Gtk.ListStore(str)
|
lb = Gtk.ListStore(str)
|
||||||
|
@ -185,7 +185,8 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
|
||||||
def _sec_labels_received(self, event):
|
def _sec_labels_received(self, event):
|
||||||
if event.account != self.account:
|
if event.account != self.account:
|
||||||
return
|
return
|
||||||
if event.jid != self.contact.jid:
|
jid = nbxmpp.JID(self.contact.jid)
|
||||||
|
if event.host != jid.getDomain():
|
||||||
return
|
return
|
||||||
lb = self.seclabel_combo.get_model()
|
lb = self.seclabel_combo.get_model()
|
||||||
lb.clear()
|
lb.clear()
|
||||||
|
@ -323,6 +324,9 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
|
||||||
self.command_hits = []
|
self.command_hits = []
|
||||||
self.last_key_tabs = False
|
self.last_key_tabs = False
|
||||||
|
|
||||||
|
# Security Labels
|
||||||
|
self.seclabel_combo = self.xml.get_object('label_selector')
|
||||||
|
|
||||||
# chatstate timers and state
|
# chatstate timers and state
|
||||||
self.reset_kbd_mouse_timeout_vars()
|
self.reset_kbd_mouse_timeout_vars()
|
||||||
self.possible_paused_timeout_id = None
|
self.possible_paused_timeout_id = None
|
||||||
|
@ -352,7 +356,7 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
|
||||||
self._nec_ping)
|
self._nec_ping)
|
||||||
app.ged.register_event_handler('ping-error', ged.GUI1,
|
app.ged.register_event_handler('ping-error', ged.GUI1,
|
||||||
self._nec_ping)
|
self._nec_ping)
|
||||||
app.ged.register_event_handler('sec-label-received', ged.GUI1,
|
app.ged.register_event_handler('sec-catalog-received', ged.GUI1,
|
||||||
self._sec_labels_received)
|
self._sec_labels_received)
|
||||||
app.ged.register_event_handler('style-changed', ged.GUI1,
|
app.ged.register_event_handler('style-changed', ged.GUI1,
|
||||||
self._style_changed)
|
self._style_changed)
|
||||||
|
@ -531,7 +535,7 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
|
||||||
'chat_control_base_draw_banner', self)
|
'chat_control_base_draw_banner', self)
|
||||||
app.ged.remove_event_handler('our-show', ged.GUI1,
|
app.ged.remove_event_handler('our-show', ged.GUI1,
|
||||||
self._nec_our_status)
|
self._nec_our_status)
|
||||||
app.ged.remove_event_handler('sec-label-received', ged.GUI1,
|
app.ged.remove_event_handler('sec-catalog-received', ged.GUI1,
|
||||||
self._sec_labels_received)
|
self._sec_labels_received)
|
||||||
app.ged.remove_event_handler('style-changed', ged.GUI1,
|
app.ged.remove_event_handler('style-changed', ged.GUI1,
|
||||||
self._style_changed)
|
self._style_changed)
|
||||||
|
@ -764,15 +768,16 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
|
||||||
ft.send_file(self.account, contact, path)
|
ft.send_file(self.account, contact, path)
|
||||||
|
|
||||||
def get_seclabel(self):
|
def get_seclabel(self):
|
||||||
label = None
|
idx = self.seclabel_combo.get_active()
|
||||||
if self.seclabel_combo is not None:
|
if idx == -1:
|
||||||
idx = self.seclabel_combo.get_active()
|
return
|
||||||
if idx != -1:
|
|
||||||
con = app.connections[self.account]
|
con = app.connections[self.account]
|
||||||
catalog = con.get_module('SecLabels').get_catalog(self.contact.jid)
|
jid = nbxmpp.JID(self.contact.jid)
|
||||||
labels, label_list, _ = catalog
|
catalog = con.get_module('SecLabels').get_catalog(jid.getDomain())
|
||||||
lname = label_list[idx]
|
labels, label_list, _ = catalog
|
||||||
label = labels[lname]
|
lname = label_list[idx]
|
||||||
|
label = labels[lname]
|
||||||
return label
|
return label
|
||||||
|
|
||||||
def send_message(self, message, keyID='', type_='chat', chatstate=None,
|
def send_message(self, message, keyID='', type_='chat', chatstate=None,
|
||||||
|
|
|
@ -42,11 +42,12 @@ class SecLabels:
|
||||||
log.info('Discovered security labels: %s', from_)
|
log.info('Discovered security labels: %s', from_)
|
||||||
|
|
||||||
def request_catalog(self, jid):
|
def request_catalog(self, jid):
|
||||||
|
jid = nbxmpp.JID(jid)
|
||||||
server = app.get_jid_from_account(self._account).split("@")[1]
|
server = app.get_jid_from_account(self._account).split("@")[1]
|
||||||
iq = nbxmpp.Iq(typ='get', to=server)
|
iq = nbxmpp.Iq(typ='get', to=server)
|
||||||
iq.addChild(name='catalog',
|
iq.addChild(name='catalog',
|
||||||
namespace=nbxmpp.NS_SECLABEL_CATALOG,
|
namespace=nbxmpp.NS_SECLABEL_CATALOG,
|
||||||
attrs={'to': jid})
|
attrs={'to': jid.getDomain()})
|
||||||
log.info('Request catalog: server: %s, to: %s', server, jid)
|
log.info('Request catalog: server: %s, to: %s', server, jid)
|
||||||
self._con.connection.SendAndCallForResponse(
|
self._con.connection.SendAndCallForResponse(
|
||||||
iq, self._catalog_received)
|
iq, self._catalog_received)
|
||||||
|
@ -73,8 +74,11 @@ class SecLabels:
|
||||||
catalog = (labels, label_list, default)
|
catalog = (labels, label_list, default)
|
||||||
self._catalogs[to] = catalog
|
self._catalogs[to] = catalog
|
||||||
|
|
||||||
|
log.info('Received catalog from %s', stanza.getFrom())
|
||||||
|
log.debug(catalog)
|
||||||
|
|
||||||
app.nec.push_incoming_event(SecLabelCatalog(
|
app.nec.push_incoming_event(SecLabelCatalog(
|
||||||
None, account=self._account, jid=to, catalog=catalog))
|
None, account=self._account, host=to, catalog=catalog))
|
||||||
|
|
||||||
def get_catalog(self, jid):
|
def get_catalog(self, jid):
|
||||||
return self._catalogs.get(jid)
|
return self._catalogs.get(jid)
|
||||||
|
|
|
@ -1017,7 +1017,7 @@ class ConversationTextview(GObject.GObject):
|
||||||
|
|
||||||
# If there's a displaymarking, print it here.
|
# If there's a displaymarking, print it here.
|
||||||
if displaymarking:
|
if displaymarking:
|
||||||
self.print_displaymarking(displaymarking, iter_=iter_)
|
self.print_displaymarking(displaymarking, iter_)
|
||||||
|
|
||||||
# kind = info, we print things as if it was a status: same color, ...
|
# kind = info, we print things as if it was a status: same color, ...
|
||||||
if kind in ('error', 'info'):
|
if kind in ('error', 'info'):
|
||||||
|
@ -1209,21 +1209,16 @@ class ConversationTextview(GObject.GObject):
|
||||||
buffer_.insert_with_tags_by_name(iter_, tim_format + '\n',
|
buffer_.insert_with_tags_by_name(iter_, tim_format + '\n',
|
||||||
'time_sometimes')
|
'time_sometimes')
|
||||||
|
|
||||||
def print_displaymarking(self, displaymarking, iter_=None):
|
def print_displaymarking(self, displaymarking, iter_):
|
||||||
bgcolor = displaymarking.getAttr('bgcolor') or '#FFF'
|
bgcolor = displaymarking.getAttr('bgcolor') or '#FFF'
|
||||||
fgcolor = displaymarking.getAttr('fgcolor') or '#000'
|
fgcolor = displaymarking.getAttr('fgcolor') or '#000'
|
||||||
text = displaymarking.getData()
|
text = displaymarking.getData()
|
||||||
if text:
|
if text:
|
||||||
buffer_ = self.tv.get_buffer()
|
buffer_ = self.tv.get_buffer()
|
||||||
if iter_:
|
|
||||||
end_iter = iter_
|
|
||||||
else:
|
|
||||||
end_iter = buffer_.get_end_iter()
|
|
||||||
tag = self.displaymarking_tags.setdefault(bgcolor + '/' + fgcolor,
|
tag = self.displaymarking_tags.setdefault(bgcolor + '/' + fgcolor,
|
||||||
buffer_.create_tag(None, background=bgcolor, foreground=fgcolor))
|
buffer_.create_tag(None, background=bgcolor, foreground=fgcolor))
|
||||||
buffer_.insert_with_tags(end_iter, '[' + text + ']', tag)
|
buffer_.insert_with_tags(iter_, '[' + text + ']', tag)
|
||||||
end_iter = buffer_.get_end_iter()
|
buffer_.insert_with_tags(iter_, ' ')
|
||||||
buffer_.insert_with_tags(end_iter, ' ')
|
|
||||||
|
|
||||||
def print_name(self, name, kind, other_tags_for_name, direction_mark='',
|
def print_name(self, name, kind, other_tags_for_name, direction_mark='',
|
||||||
iter_=None):
|
iter_=None):
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!-- Generated with glade 3.21.0 -->
|
<!-- Generated with glade 3.22.1 -->
|
||||||
<interface>
|
<interface>
|
||||||
<requires lib="gtk+" version="3.20"/>
|
<requires lib="gtk+" version="3.20"/>
|
||||||
<object class="GtkAdjustment" id="adjustment1">
|
<object class="GtkAdjustment" id="adjustment1">
|
||||||
|
@ -24,6 +24,9 @@
|
||||||
<property name="skip_pager_hint">True</property>
|
<property name="skip_pager_hint">True</property>
|
||||||
<property name="decorated">False</property>
|
<property name="decorated">False</property>
|
||||||
<property name="deletable">False</property>
|
<property name="deletable">False</property>
|
||||||
|
<child type="titlebar">
|
||||||
|
<placeholder/>
|
||||||
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkGrid" id="grid1">
|
<object class="GtkGrid" id="grid1">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
|
@ -278,9 +281,6 @@
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
<child type="titlebar">
|
|
||||||
<placeholder/>
|
|
||||||
</child>
|
|
||||||
</object>
|
</object>
|
||||||
<object class="GtkMenu" id="formattings_menu">
|
<object class="GtkMenu" id="formattings_menu">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
|
@ -639,7 +639,7 @@
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="expand">True</property>
|
<property name="expand">False</property>
|
||||||
<property name="fill">True</property>
|
<property name="fill">True</property>
|
||||||
<property name="pack_type">end</property>
|
<property name="pack_type">end</property>
|
||||||
<property name="position">0</property>
|
<property name="position">0</property>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!-- Generated with glade 3.21.0 -->
|
<!-- Generated with glade 3.22.1 -->
|
||||||
<interface>
|
<interface>
|
||||||
<requires lib="gtk+" version="3.20"/>
|
<requires lib="gtk+" version="3.20"/>
|
||||||
<object class="GtkMenu" id="formattings_menu">
|
<object class="GtkMenu" id="formattings_menu">
|
||||||
|
@ -386,7 +386,7 @@
|
||||||
<property name="no_show_all">True</property>
|
<property name="no_show_all">True</property>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="expand">True</property>
|
<property name="expand">False</property>
|
||||||
<property name="fill">True</property>
|
<property name="fill">True</property>
|
||||||
<property name="position">7</property>
|
<property name="position">7</property>
|
||||||
</packing>
|
</packing>
|
||||||
|
|
|
@ -454,7 +454,7 @@ class GroupchatControl(ChatControlBase):
|
||||||
column.set_visible(False)
|
column.set_visible(False)
|
||||||
self.list_treeview.set_expander_column(column)
|
self.list_treeview.set_expander_column(column)
|
||||||
|
|
||||||
self.setup_seclabel(self.xml.get_object('label_selector'))
|
self.setup_seclabel()
|
||||||
|
|
||||||
self.form_widget = None
|
self.form_widget = None
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue