def command_set(self, args): """ /set [module|][section] <option> [value] """ if len(args) == 1: option = args[0] value = config.get(option) info = ('%s=%s' % (option, value), 'Info') elif len(args) == 2: if '|' in args[0]: plugin_name, section = args[0].split('|')[:2] if not section: section = plugin_name option = args[1] if not plugin_name in self.plugin_manager.plugins: file_name = self.plugin_manager.plugins_conf_dir file_name = os.path.join(file_name, plugin_name + '.cfg') plugin_config = PluginConfig(file_name, plugin_name) else: plugin_config = self.plugin_manager.plugins[plugin_name].config value = plugin_config.get(option, default='', section=section) info = ('%s=%s' % (option, value), 'Info') else: possible_section = args[0] if config.has_section(possible_section): section = possible_section option = args[1] value = config.get(option, section=section) info = ('%s=%s' % (option, value), 'Info') else: option = args[0] value = args[1] info = config.set_and_save(option, value) self.trigger_configuration_change(option, value) elif len(args) == 3: if '|' in args[0]: plugin_name, section = args[0].split('|')[:2] if not section: section = plugin_name option = args[1] value = args[2] if not plugin_name in self.plugin_manager.plugins: file_name = self.plugin_manager.plugins_conf_dir file_name = os.path.join(file_name, plugin_name + '.cfg') plugin_config = PluginConfig(file_name, plugin_name) else: plugin_config = self.plugin_manager.plugins[plugin_name].config info = plugin_config.set_and_save(option, value, section) else: section = args[0] option = args[1] value = args[2] info = config.set_and_save(option, value, section) self.trigger_configuration_change(option, value) else: return self.command_help('set') self.call_for_resize() self.information(*info)
def local(self): """Generate a str for local storage""" local = self.jid if self.nick: local += "/%s" % self.nick local += ":" if self.password: config.set_and_save("password", self.password, section=self.jid) return local
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) config.set_and_save('folded_roster_groups', folded_groups, 'var')
def local(self): """Generate a str for local storage""" local = self.jid if self.nick: local += '/%s' % self.nick local += ':' if self.password: config.set_and_save('password', self.password, section=self.jid) return local
def save_bookmarks_method(available_methods): pep, privatexml = available_methods["pep"], available_methods["privatexml"] if pep and not privatexml: config.set_and_save('use_bookmarks_method', 'pep') elif privatexml and not pep: config.set_and_save('use_bookmarks_method', 'privatexml') elif not pep and not privatexml: config.set_and_save('use_bookmarks_method', '')
def get_remote(xmpp): """Add the remotely stored bookmarks to the list.""" if xmpp.anon: return pep, privatexml = True, True for method in methods[1:]: if method == 'pep': pep = get_pep(xmpp) else: privatexml = get_privatexml(xmpp) if pep and not privatexml: config.set_and_save('use_bookmarks_method', 'pep') elif privatexml and not pep: config.set_and_save('use_bookmarks_method', 'privatexml') elif not pep and not privatexml: config.set_and_save('use_bookmarks_method', '')
def save_local(self): """Save the local bookmarks.""" local = "".join(bookmark.local() for bookmark in self if bookmark.method == "local") config.set_and_save("rooms", local)
def set_bookmarks_method(self, value): if self.available_storage.get(value): self.preferred = value config.set_and_save("use_bookmarks_method", value)
def command_set(self, args): """ /set [module|][section] <option> [value] """ if args is None or len(args) == 0: config_dict = config.to_dict() lines = [] theme = get_theme() for section_name, section in config_dict.items(): lines.append( '\x19%(section_col)s}[%(section)s]\x19o' % { 'section': section_name, 'section_col': dump_tuple(theme.COLOR_INFORMATION_TEXT), }) for option_name, option_value in section.items(): lines.append( '%s\x19%s}=\x19o%s' % (option_name, dump_tuple( theme.COLOR_REVISIONS_MESSAGE), option_value)) info = ('Current options:\n%s' % '\n'.join(lines), 'Info') elif len(args) == 1: option = args[0] value = config.get(option) if value is None and '=' in option: args = option.split('=', 1) info = ('%s=%s' % (option, value), 'Info') if len(args) == 2: if '|' in args[0]: plugin_name, section = args[0].split('|')[:2] if not section: section = plugin_name option = args[1] if not plugin_name in self.plugin_manager.plugins: file_name = self.plugin_manager.plugins_conf_dir file_name = os.path.join(file_name, plugin_name + '.cfg') plugin_config = PluginConfig(file_name, plugin_name) else: plugin_config = self.plugin_manager.plugins[plugin_name].config value = plugin_config.get(option, default='', section=section) info = ('%s=%s' % (option, value), 'Info') else: possible_section = args[0] if config.has_section(possible_section): section = possible_section option = args[1] value = config.get(option, section=section) info = ('%s=%s' % (option, value), 'Info') else: option = args[0] value = args[1] info = config.set_and_save(option, value) self.trigger_configuration_change(option, value) elif len(args) == 3: if '|' in args[0]: plugin_name, section = args[0].split('|')[:2] if not section: section = plugin_name option = args[1] value = args[2] if not plugin_name in self.plugin_manager.plugins: file_name = self.plugin_manager.plugins_conf_dir file_name = os.path.join(file_name, plugin_name + '.cfg') plugin_config = PluginConfig(file_name, plugin_name) else: plugin_config = self.plugin_manager.plugins[plugin_name].config info = plugin_config.set_and_save(option, value, section) else: if args[0] == '.': name = safeJID(self.current_tab().name).bare if not name: self.information('Invalid tab to use the "." argument.', 'Error') return section = name else: section = args[0] option = args[1] value = args[2] info = config.set_and_save(option, value, section) self.trigger_configuration_change(option, value) elif len(args) > 3: return self.command_help('set') self.information(*info)
def save_local(self): """Save the local bookmarks.""" local = ''.join(bookmark.local() for bookmark in self if bookmark.method == 'local') config.set_and_save('rooms', local)
def set_bookmarks_method(self, value): if self.available_storage.get(value): self.preferred = value config.set_and_save('use_bookmarks_method', value)
def command_set(self, args): """ /set [module|][section] <option> [value] """ if args is None or len(args) == 0: config_dict = config.to_dict() lines = [] theme = get_theme() for section_name, section in config_dict.items(): lines.append('\x19%(section_col)s}[%(section)s]\x19o' % { 'section': section_name, 'section_col': dump_tuple(theme.COLOR_INFORMATION_TEXT), }) for option_name, option_value in section.items(): lines.append('%s\x19%s}=\x19o%s' % (option_name, dump_tuple(theme.COLOR_REVISIONS_MESSAGE), option_value)) info = ('Current options:\n%s' % '\n'.join(lines), 'Info') elif len(args) == 1: option = args[0] value = config.get(option) if value is None and '=' in option: args = option.split('=', 1) info = ('%s=%s' % (option, value), 'Info') if len(args) == 2: if '|' in args[0]: plugin_name, section = args[0].split('|')[:2] if not section: section = plugin_name option = args[1] if not plugin_name in self.plugin_manager.plugins: file_name = self.plugin_manager.plugins_conf_dir file_name = os.path.join(file_name, plugin_name + '.cfg') plugin_config = PluginConfig(file_name, plugin_name) else: plugin_config = self.plugin_manager.plugins[plugin_name].config value = plugin_config.get(option, default='', section=section) info = ('%s=%s' % (option, value), 'Info') else: possible_section = args[0] if config.has_section(possible_section): section = possible_section option = args[1] value = config.get(option, section=section) info = ('%s=%s' % (option, value), 'Info') else: option = args[0] value = args[1] info = config.set_and_save(option, value) self.trigger_configuration_change(option, value) elif len(args) == 3: if '|' in args[0]: plugin_name, section = args[0].split('|')[:2] if not section: section = plugin_name option = args[1] value = args[2] if not plugin_name in self.plugin_manager.plugins: file_name = self.plugin_manager.plugins_conf_dir file_name = os.path.join(file_name, plugin_name + '.cfg') plugin_config = PluginConfig(file_name, plugin_name) else: plugin_config = self.plugin_manager.plugins[plugin_name].config info = plugin_config.set_and_save(option, value, section) else: if args[0] == '.': name = safeJID(self.current_tab().name).bare if not name: self.information(_('Invalid tab to use the "." argument.'), _('Error')) return section = name else: section = args[0] option = args[1] value = args[2] info = config.set_and_save(option, value, section) self.trigger_configuration_change(option, value) elif len(args) > 3: return self.command_help('set') self.call_for_resize() self.information(*info)
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')
def save_local(): """Save the local bookmarks.""" all = ''.join(bookmark.local() for bookmark in bookmarks if bookmark.method is 'local') config.set_and_save('rooms', all)