def __async_rpc_cb_changed_url_hostname(self, hostname, results): self._cache_hostname[hostname] = results templates = results['siteTemplates'] combobox = self.gobjects['combobox_url_path'] combobox.set_property('button-sensitivity', templates['total'] > 0) model = combobox.get_model() model.clear() for template in templates['edges']: template = template['node'] path = utilities.make_webrelpath(template['path']) if path and not path.endswith(webpath.sep): path += webpath.sep for page in template['metadata']['pages']: model.append((path + utilities.make_webrelpath(page), path)) # this is going to trigger a changed signal and the cascade effect will update the URL information and preview combobox.set_active_id( utilities.make_webrelpath( gui_utilities.gtk_combobox_get_entry_text(combobox))) sni_hostname = results['ssl']['sniHostname'] label = self.gobjects['label_url_ssl_status'] if sni_hostname is None: _set_icon(self.gobjects['image_url_ssl_status'], 'gtk-no') label.set_text( 'There is no certificate available for the specified hostname') if self._can_issue_certs: self.gobjects[ 'button_url_ssl_issue_certificate'].set_sensitive(True) else: _set_icon(self.gobjects['image_url_ssl_status'], 'gtk-yes') label.set_text( 'A certificate for the specified hostname is available')
def _set_webserver_url(self, webserver_url): webserver_url = urllib.parse.urlparse(webserver_url.strip()) if webserver_url.scheme == 'http': self.gobjects['combobox_url_scheme'].set_active_id( 'http/' + str(webserver_url.port or 80)) elif webserver_url.scheme == 'https': self.gobjects['combobox_url_scheme'].set_active_id( 'https/' + str(webserver_url.port or 443)) if webserver_url.hostname: self.gobjects['combobox_url_hostname'].get_child().set_text( webserver_url.hostname) if webserver_url.path: self.gobjects['combobox_url_path'].get_child().set_text( utilities.make_webrelpath(webserver_url.path))
def _load_metadata(path): file_path, loader = _find_metadata(path) if file_path is None: logger.info('found no metadata file for path: ' + path) return with open(file_path, 'r') as file_h: metadata = loader(file_h) # manually set the version to a string so the input format is more forgiving if isinstance(metadata.get('version'), (float, int)): metadata['version'] = str(metadata['version']) try: utilities.validate_json_schema(metadata, 'king-phisher.template.site.metadata') except jsonschema.exceptions.ValidationError: logger.error("template metadata file: {0} failed to pass schema validation".format(file_path), exc_info=True) return None metadata['pages'] = [utilities.make_webrelpath(path) for path in metadata['pages']] return metadata
def signal_combobox_changed_set_url_information(self, _): for label in ('info_title', 'info_authors', 'info_created', 'info_description'): self.gobjects['label_url_' + label].set_text('') hostname = gui_utilities.gtk_combobox_get_entry_text( self.gobjects['combobox_url_hostname']) if not hostname: return combobox_url_path = self.gobjects['combobox_url_path'] path = gui_utilities.gtk_combobox_get_active_cell(combobox_url_path, column=1) if path is None: model = combobox_url_path.get_model() text = utilities.make_webrelpath( gui_utilities.gtk_combobox_get_entry_text(combobox_url_path)) row_iter = gui_utilities.gtk_list_store_search(model, text) if row_iter: path = model[row_iter][1] gui_utilities.gtk_widget_destroy_children( self.gobjects['listbox_url_info_classifiers']) gui_utilities.gtk_widget_destroy_children( self.gobjects['listbox_url_info_references']) cached_result = self._cache_site_template.get((hostname, path)) if cached_result: self.__async_rpc_cb_populate_url_info(hostname, path, cached_result) return self.application.rpc.async_graphql( """ query getSiteTemplate($hostname: String, $path: String) { siteTemplate(hostname: $hostname, path: $path) { created path metadata { title authors description referenceUrls classifiers pages } } } """, query_vars={ 'hostname': hostname, 'path': path }, on_success=self.__async_rpc_cb_populate_url_info, cb_args=(hostname, path), when_idle=True)
def signal_combobox_changed_set_url_preview(self, _): label = self.gobjects['label_url_preview'] label.set_text('') combobox_url_scheme = self.gobjects['combobox_url_scheme'] active = combobox_url_scheme.get_active() if active == -1: return url_scheme = _ModelURLScheme(*combobox_url_scheme.get_model()[active]) authority = gui_utilities.gtk_combobox_get_entry_text( self.gobjects['combobox_url_hostname']) path = gui_utilities.gtk_combobox_get_entry_text( self.gobjects['combobox_url_path']) if url_scheme and authority: path = utilities.make_webrelpath(path) if (url_scheme.name == 'http' and url_scheme.port != 80) or (url_scheme.name == 'https' and url_scheme.port != 443): authority += ':' + str(url_scheme.port) label.set_text("{}://{}/{}".format(url_scheme.name, authority, path))