Exemplo n.º 1
0
    def import_message_data(self):
        """
		Process a previously exported message archive file and restore the
		message data, settings, and applicable files from it.
		"""
        config_tab = self.tabs.get('config')
        if not config_tab:
            self.logger.warning(
                'attempted to import message data while the config tab was unavailable'
            )
            return
        config_prefix = config_tab.config_prefix
        config_tab.objects_save_to_config()
        dialog = gui_utilities.UtilityFileChooser(
            'Import Message Configuration', self.parent)
        dialog.quick_add_filter('King Phisher Message Files', '*.kpm')
        dialog.quick_add_filter('All Files', '*')
        response = dialog.run_quick_open()
        dialog.destroy()
        if not response:
            return
        target_file = response['target_path']

        dialog = gui_utilities.UtilityFileChooser('Destination Directory',
                                                  self.parent)
        response = dialog.run_quick_select_directory()
        dialog.destroy()
        if not response:
            return
        dest_dir = response['target_path']
        try:
            message_data = export.message_data_from_kpm(target_file, dest_dir)
        except KingPhisherInputValidationError as error:
            gui_utilities.show_dialog_error('Import Error', self.parent,
                                            error.message.capitalize() + '.')
            return

        config_keys = set(
            filter(lambda k: k.startswith(config_prefix), self.config.keys()))
        config_types = dict(zip(config_keys, map(type, config_keys)))
        for key, value in message_data.items():
            key = config_prefix + key
            if not key in config_keys:
                continue
            self.config[key] = value
            config_keys.remove(key)
        for unset_key in config_keys:
            config_type = config_types[unset_key]
            if not config_type in (bool, dict, int, list, str, tuple):
                continue
            self.config[unset_key] = config_type()
        config_tab.objects_load_from_config()
        gui_utilities.show_dialog_info('Successfully imported the message',
                                       self.parent)
Exemplo n.º 2
0
    def export_message_data(self):
        """
		Gather and prepare the components of the mailer tab to be exported into
		a message archive file suitable for restoring at a later point in time.
		"""
        config_tab = self.tabs.get('config')
        if not config_tab:
            self.logger.warning(
                'attempted to export message data while the config tab was unavailable'
            )
            return
        config_prefix = config_tab.config_prefix
        config_tab.objects_save_to_config()
        dialog = gui_utilities.UtilityFileChooser(
            'Export Message Configuration', self.parent)
        response = dialog.run_quick_save('message.kpm')
        dialog.destroy()
        if not response:
            return
        message_config = {}
        config_keys = filter(lambda k: k.startswith(config_prefix),
                             self.config.keys())
        for config_key in config_keys:
            message_config[config_key[7:]] = self.config[config_key]
        export.message_data_to_kpm(message_config, response['target_path'])
Exemplo n.º 3
0
 def signal_multi_set_directory(self, _):
     dialog = gui_utilities.UtilityFileChooser('Destination Directory',
                                               self.dialog)
     response = dialog.run_quick_select_directory()
     dialog.destroy()
     if response:
         self.entry_directory.set_text(response['target_path'])
Exemplo n.º 4
0
 def signal_activate_popup_menu_export(self, action):
     dialog = gui_utilities.UtilityFileChooser('Export Graph', self.parent)
     file_name = self.config['campaign_name'] + '.png'
     response = dialog.run_quick_save(file_name)
     dialog.destroy()
     if not response:
         return
     destination_file = response['target_path']
     self.figure.savefig(destination_file, format='png')
Exemplo n.º 5
0
 def export_campaign_xml(self):
     """Export the current campaign to an XML data file."""
     dialog = gui_utilities.UtilityFileChooser('Export Campaign XML Data',
                                               self)
     file_name = self.config['campaign_name'] + '.xml'
     response = dialog.run_quick_save(file_name)
     dialog.destroy()
     if not response:
         return
     destination_file = response['target_path']
     export.campaign_to_xml(self.rpc, self.config['campaign_id'],
                            destination_file)
Exemplo n.º 6
0
	def signal_button_clicked_export(self, button):
		if isinstance(self.loader_thread, threading.Thread) and self.loader_thread.is_alive():
			gui_utilities.show_dialog_warning('Can Not Export Rows While Loading', self.parent)
			return
		dialog = gui_utilities.UtilityFileChooser('Export Data', self.parent)
		file_name = self.config['campaign_name'] + '.csv'
		response = dialog.run_quick_save(file_name)
		dialog.destroy()
		if not response:
			return
		destination_file = response['target_path']
		export.treeview_liststore_to_csv(self.gobjects['treeview_campaign'], destination_file)
Exemplo n.º 7
0
 def signal_entry_activate_open_file(self, entry):
     dialog = gui_utilities.UtilityFileChooser('Choose File')
     if entry == self.gobjects.get('entry_html_file'):
         dialog.quick_add_filter('HTML Files', ['*.htm', '*.html'])
     elif entry == self.gobjects.get('entry_target_file'):
         dialog.quick_add_filter('CSV Files', '*.csv')
     dialog.quick_add_filter('All Files', '*')
     response = dialog.run_quick_open()
     dialog.destroy()
     if not response:
         return False
     entry.set_text(response['target_path'])
     return True
Exemplo n.º 8
0
 def signal_activate_popup_menu_insert_image(self, widget):
     dialog = gui_utilities.UtilityFileChooser('Choose Image')
     dialog.quick_add_filter('Images',
                             ['*.gif', '*.jpeg', '*.jpg', '*.png'])
     dialog.quick_add_filter('All Files', '*')
     response = dialog.run_quick_open()
     dialog.destroy()
     if not response:
         return
     target_path = response['target_path']
     target_path = utilities.escape_single_quote(target_path)
     text = "{{{{ inline_image('{0}') }}}}".format(target_path)
     return self.signal_activate_popup_menu_insert(widget, text)
Exemplo n.º 9
0
 def signal_button_save_as(self, button):
     html_file = self.config.get('mailer.html_file')
     if not html_file:
         return
     dialog = gui_utilities.UtilityFileChooser('Save HTML File',
                                               self.parent)
     response = dialog.run_quick_save(
         current_name=os.path.basename(html_file))
     dialog.destroy()
     if not response:
         return
     destination_file = response['target_path']
     text = self.textbuffer.get_text(self.textbuffer.get_start_iter(),
                                     self.textbuffer.get_end_iter(), False)
     html_file_h = open(destination_file, 'w')
     html_file_h.write(text)
     html_file_h.close()
     self.config['mailer.html_file'] = destination_file