From 65362358a9e0a4097d88761c65bf6a64c63838fe Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Wed, 4 Jan 2017 13:13:55 +0100 Subject: [PATCH] ability to have a random string in the resource --- src/common/config.py | 2 +- src/common/connection.py | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/common/config.py b/src/common/config.py index 79368347a..c9e308a42 100644 --- a/src/common/config.py +++ b/src/common/config.py @@ -325,7 +325,7 @@ class Config: 'client_cert_encrypted': [ opt_bool, False, '', False ], 'savepass': [ opt_bool, False ], 'password': [ opt_str, '' ], - 'resource': [ opt_str, 'gajim', '', True ], + 'resource': [ opt_str, 'gajim.$rand', '', True ], 'priority': [ opt_int, 5, '', True ], 'adjust_priority_with_status': [ opt_bool, True, _('Priority will change automatically according to your status. Priorities are defined in autopriority_* options.') ], 'autopriority_online': [ opt_int, 50], diff --git a/src/common/connection.py b/src/common/connection.py index 3e943b02d..644574423 100644 --- a/src/common/connection.py +++ b/src/common/connection.py @@ -36,7 +36,7 @@ import os import random import socket import operator - +import string import time import locale import hmac @@ -182,8 +182,10 @@ class CommonConnection: resource = gajim.config.get_per('accounts', self.name, 'resource') # All valid resource substitution strings should be added to this hash. if resource: + rand = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(8)) resource = Template(resource).safe_substitute({ - 'hostname': socket.gethostname() + 'hostname': socket.gethostname(), + 'rand': rand }) return resource