def callback(iq): if iq['type'] == 'result': self.core.information('Password updated', 'Account') if config.get('password'): config.silent_set('password', args[0]) else: self.core.information('Unable to change the password', 'Account')
def save_to_config_file(self): """ Save various information to the config file e.g. the folded groups """ folded_groups = ':'.join([group.name for group in self.groups.values()\ if group.folded]) log.debug('folded:%s\n', folded_groups) return config.silent_set('folded_roster_groups', folded_groups, 'var')
def toggle_offline_show(self): """ Show or hide offline contacts """ option = 'roster_show_offline' value = config.get(option) success = config.silent_set(option, str(not value)) roster.modified() if not success: self.core.information('Unable to write in the config file', 'Error') return True
def toggle_offline_show(self): """ Show or hide offline contacts """ option = 'roster_show_offline' value = config.get(option) success = config.silent_set(option, str(not value)) roster.modified() if not success: self.core.information(_('Unable to write in the config file'), 'Error') return True
def command_bind(self, args): """ Bind a key. """ if args is None: return self.command_help('bind') if not config.silent_set(args[0], args[1], section='bindings'): self.information('Unable to write in the config file', 'Error') if args[1]: self.information('%s is now bound to %s' % (args[0], args[1]), 'Info') else: self.information('%s is now unbound' % args[0], 'Info')
def command_bind(self, args): """ Bind a key. """ if args is None: return self.command_help('bind') if not config.silent_set(args[0], args[1], section='bindings'): self.information(_('Unable to write in the config file'), 'Error') if args[1]: self.information('%s is now bound to %s' % (args[0], args[1]), 'Info') else: self.information('%s is now unbound' % args[0], 'Info')
def check_input(future): while input.value is None: yield from asyncio.sleep(0.01) self.current_tab().input = saved_input self.paused = False if input.value: self.information('Setting new certificate: old: %s, new: %s' % (cert, sha2_found_cert), 'Info') log.debug('Setting certificate to %s', sha2_found_cert) if not config.silent_set('certificate', sha2_found_cert): self.information(_('Unable to write in the config file'), 'Error') else: self.information('You refused to validate the certificate. You are now disconnected', 'Info') self.disconnect() new_loop.stop() asyncio.set_event_loop(old_loop)
def validate_ssl(self, pem): """ Check the server certificate using the slixmpp ssl_cert event """ if config.get('ignore_certificate'): return cert = config.get('certificate') # update the cert representation when it uses the old one if cert and not ':' in cert: cert = ':'.join(i + j for i, j in zip(cert[::2], cert[1::2])).upper() config.set_and_save('certificate', cert) der = ssl.PEM_cert_to_DER_cert(pem) sha1_digest = sha1(der).hexdigest().upper() sha1_found_cert = ':'.join(i + j for i, j in zip(sha1_digest[::2], sha1_digest[1::2])) sha2_digest = sha512(der).hexdigest().upper() sha2_found_cert = ':'.join(i + j for i, j in zip(sha2_digest[::2], sha2_digest[1::2])) if cert: if sha1_found_cert == cert: log.debug('Cert %s OK', sha1_found_cert) log.debug('Current hash is SHA-1, moving to SHA-2 (%s)', sha2_found_cert) config.set_and_save('certificate', sha2_found_cert) return elif sha2_found_cert == cert: log.debug('Cert %s OK', sha2_found_cert) return else: saved_input = self.current_tab().input log.debug('\nWARNING: CERTIFICATE CHANGED old: %s, new: %s\n', cert, sha2_found_cert) self.information('New certificate found (sha-2 hash:' ' %s)\nPlease validate or abort' % sha2_found_cert, 'Warning') input = windows.YesNoInput(text="WARNING! Server certificate has changed, accept? (y/n)") self.current_tab().input = input input.resize(1, self.current_tab().width, self.current_tab().height-1, 0) input.refresh() self.doupdate() old_loop = asyncio.get_event_loop() new_loop = asyncio.new_event_loop() asyncio.set_event_loop(new_loop) new_loop.add_reader(sys.stdin, self.on_input_readable) future = asyncio.Future() @asyncio.coroutine def check_input(future): while input.value is None: yield from asyncio.sleep(0.01) self.current_tab().input = saved_input self.paused = False if input.value: self.information('Setting new certificate: old: %s, new: %s' % (cert, sha2_found_cert), 'Info') log.debug('Setting certificate to %s', sha2_found_cert) if not config.silent_set('certificate', sha2_found_cert): self.information(_('Unable to write in the config file'), 'Error') else: self.information('You refused to validate the certificate. You are now disconnected', 'Info') self.disconnect() new_loop.stop() asyncio.set_event_loop(old_loop) asyncio.async(check_input(future)) new_loop.run_forever() else: log.debug('First time. Setting certificate to %s', sha2_found_cert) if not config.silent_set('certificate', sha2_found_cert): self.information(_('Unable to write in the config file'), 'Error')