From 520bc6b2688759caeb7bef4b38e18cf4bb4cd81e Mon Sep 17 00:00:00 2001
From: Yann Leboulanger <asterix@lagaule.org>
Date: Mon, 31 Oct 2011 09:47:01 +0100
Subject: [PATCH] change the insecure connection dialog behaviour. Fixes #7019

---
 src/common/config.py     |  2 +-
 src/common/connection.py |  8 +++++++-
 src/dialogs.py           |  7 ++++++-
 src/gui_interface.py     | 15 ++++++++++-----
 4 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/src/common/config.py b/src/common/config.py
index 5d7d40c866..9ef46b6372 100644
--- a/src/common/config.py
+++ b/src/common/config.py
@@ -323,7 +323,7 @@ class Config:
                     'enable_esessions': [opt_bool, True, _('Enable ESessions encryption for this account.')],
                     'autonegotiate_esessions': [opt_bool, True, _('Should Gajim automatically start an encrypted session when possible?')],
                     'connection_types': [ opt_str, 'tls ssl plain', _('Ordered list (space separated) of connection type to try. Can contain tls, ssl or plain')],
-                    'warn_when_plaintext_connection': [ opt_bool, True, _('Show a warning dialog before sending password on an plaintext connection.') ],
+                    'action_when_plaintext_connection': [ opt_str, 'warn', _('Show a warning dialog before sending password on an plaintext connection. Can be \'warn\', \'connect\', \'disconnect\'') ],
                     'warn_when_insecure_ssl_connection': [ opt_bool, True, _('Show a warning dialog before using standard SSL library.') ],
                     'warn_when_insecure_password': [ opt_bool, True, _('Show a warning dialog before sending PLAIN password over a plain connection.') ],
                     'ssl_fingerprint_sha1': [ opt_str, '', '', True ],
diff --git a/src/common/connection.py b/src/common/connection.py
index 0179edd38d..ca9323479f 100644
--- a/src/common/connection.py
+++ b/src/common/connection.py
@@ -1254,10 +1254,16 @@ class Connection(CommonConnection, ConnectionHandlers):
             return
         con.RegisterDisconnectHandler(self._on_disconnected)
         if _con_type == 'plain' and gajim.config.get_per('accounts', self.name,
-        'warn_when_plaintext_connection'):
+        'action_when_plaintext_connection') == 'warn':
             gajim.nec.push_incoming_event(PlainConnectionEvent(None, conn=self,
                 xmpp_client=con))
             return True
+        if _con_type == 'plain' and gajim.config.get_per('accounts', self.name,
+        'action_when_plaintext_connection') == 'disconnect':
+            self.disconnect(on_purpose=True)
+            gajim.nec.push_incoming_event(OurShowEvent(None, conn=self,
+                show='offline'))
+            return False
         if _con_type in ('tls', 'ssl') and con.Connection.ssl_lib != 'PYOPENSSL' \
         and gajim.config.get_per('accounts', self.name,
         'warn_when_insecure_ssl_connection') and \
diff --git a/src/dialogs.py b/src/dialogs.py
index 228c997807..e81b8b8967 100644
--- a/src/dialogs.py
+++ b/src/dialogs.py
@@ -1722,7 +1722,8 @@ class ConfirmationDialogDoubleCheck(ConfirmationDialog):
     """
 
     def __init__(self, pritext, sectext='', checktext1='', checktext2='',
-            on_response_ok=None, on_response_cancel=None, is_modal=True):
+    tooltip1='', tooltip2='', on_response_ok=None, on_response_cancel=None,
+    is_modal=True):
         self.user_response_ok = on_response_ok
         self.user_response_cancel = on_response_cancel
 
@@ -1741,11 +1742,15 @@ class ConfirmationDialogDoubleCheck(ConfirmationDialog):
 
         if checktext1:
             self.checkbutton1 = gtk.CheckButton(checktext1)
+            if tooltip1:
+                self.checkbutton1.set_tooltip_text(tooltip1)
             self.vbox.pack_start(self.checkbutton1, expand=False, fill=True)
         else:
             self.checkbutton1 = None
         if checktext2:
             self.checkbutton2 = gtk.CheckButton(checktext2)
+            if tooltip2:
+                self.checkbutton2.set_tooltip_text(tooltip2)
             self.vbox.pack_start(self.checkbutton2, expand=False, fill=True)
         else:
             self.checkbutton2 = None
diff --git a/src/gui_interface.py b/src/gui_interface.py
index 92bc7a8bec..a6598e4608 100644
--- a/src/gui_interface.py
+++ b/src/gui_interface.py
@@ -1249,6 +1249,9 @@ class Interface:
         # ('PLAIN_CONNECTION', account, (connection))
         def on_ok(is_checked):
             if not is_checked[0]:
+                if is_checked[1]:
+                    gajim.config.set_per('accounts', obj.conn.name,
+                        'action_when_plaintext_connection', 'disconnect')
                 on_cancel()
                 return
             # On cancel call del self.instances, so don't call it another time
@@ -1257,7 +1260,7 @@ class Interface:
                 ['plain_connection']
             if is_checked[1]:
                 gajim.config.set_per('accounts', obj.conn.name,
-                    'warn_when_plaintext_connection', False)
+                    'action_when_plaintext_connection', 'connect')
             obj.conn.connection_accepted(obj.xmpp_client, 'plain')
 
         def on_cancel():
@@ -1270,18 +1273,20 @@ class Interface:
         pritext = _('Insecure connection')
         sectext = _('You are about to connect to the account %(account)s '
             '(%(server)s) with an insecure connection. This means all your '
-            'conversations will be exchanged unencrypted. Are you sure you '
-            'want to do that?') % {'account': obj.conn.name,
+            'conversations will be exchanged unencrypted. This type of '
+            'connection is really discouraged.\nAre you sure you want to do '
+            'that?') % {'account': obj.conn.name,
             'server': gajim.get_hostname_from_account(obj.conn.name)}
         checktext1 = _('Yes, I really want to connect insecurely')
+        tooltip1 = _('Gajim will NOT connect unless you check this box')
         checktext2 = _('_Do not ask me again')
         if 'plain_connection' in self.instances[obj.conn.name]['online_dialog']:
             self.instances[obj.conn.name]['online_dialog']['plain_connection'].\
                 destroy()
         self.instances[obj.conn.name]['online_dialog']['plain_connection'] = \
             dialogs.ConfirmationDialogDoubleCheck(pritext, sectext, checktext1,
-            checktext2, on_response_ok=on_ok, on_response_cancel=on_cancel,
-            is_modal=False)
+            checktext2, tooltip1=tooltip1, on_response_ok=on_ok,
+            on_response_cancel=on_cancel, is_modal=False)
 
     def handle_event_insecure_ssl_connection(self, obj):
         # ('INSECURE_SSL_CONNECTION', account, (connection, connection_type))
-- 
GitLab