Пример #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.FileChooser('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.FileChooser('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(key for key in self.config.keys()
                          if key.startswith(config_prefix))
        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)
Пример #2
0
 def signal_multi_set_directory(self, _):
     dialog = gui_utilities.FileChooser('Destination Directory',
                                        self.dialog)
     response = dialog.run_quick_select_directory()
     dialog.destroy()
     if response:
         self.entry_directory.set_text(response['target_path'])
Пример #3
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.FileChooser('Export Message Configuration',
                                           self.parent)
        response = dialog.run_quick_save('message.kpm')
        dialog.destroy()
        if not response:
            return
        message_config = {}
        config_keys = (key for key in self.config.keys()
                       if key.startswith(config_prefix))
        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'])
Пример #4
0
	def signal_activate_popup_menu_export(self, action):
		dialog = gui_utilities.FileChooser('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')
Пример #5
0
 def export_campaign_xml(self):
     """Export the current campaign to an XML data file."""
     dialog = gui_utilities.FileChooser('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)
Пример #6
0
 def signal_toolbutton_open(self, button):
     dialog = gui_utilities.FileChooser('Choose File', self.parent)
     dialog.quick_add_filter('HTML Files', ['*.htm', '*.html'])
     dialog.quick_add_filter('All Files', '*')
     response = dialog.run_quick_open()
     dialog.destroy()
     if not response:
         return False
     self.config['mailer.html_file'] = response['target_path']
     self.show_tab()
     return True
Пример #7
0
 def signal_entry_activate_open_file(self, entry):
     dialog = gui_utilities.FileChooser('Choose File', self.parent)
     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
Пример #8
0
 def signal_activate_popup_menu_insert_image(self, widget):
     dialog = gui_utilities.FileChooser('Choose Image', self.parent)
     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)
Пример #9
0
    def export_campaign_visit_geojson(self):
        """
		Export the current campaign visit information to a GeoJSON data file.
		"""
        dialog = gui_utilities.FileChooser(
            'Export Campaign Visit GeoJSON Data', self)
        file_name = self.config['campaign_name'] + '.geojson'
        response = dialog.run_quick_save(file_name)
        dialog.destroy()
        if not response:
            return
        destination_file = response['target_path']
        export.campaign_visits_to_geojson(self.rpc, self.config['campaign_id'],
                                          destination_file)
Пример #10
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.FileChooser('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)
Пример #11
0
 def export_campaign_xlsx(self):
     """Export the current campaign to an Excel compatible XLSX workbook."""
     dialog = gui_utilities.FileChooser('Export Campaign To Excel', self)
     file_name = self.config['campaign_name'] + '.xlsx'
     response = dialog.run_quick_save(file_name)
     dialog.destroy()
     if not response:
         return
     destination_file = response['target_path']
     campaign_tab = self.tabs['campaign']
     workbook = xlsxwriter.Workbook(destination_file)
     for tab_name, tab in campaign_tab.tabs.items():
         if not isinstance(tab, CampaignViewGenericTableTab):
             continue
         tab.export_table_to_xlsx_worksheet(
             workbook.add_worksheet(tab_name))
     workbook.close()
Пример #12
0
	def export_table_to_csv(self):
		"""Export the data represented by the view to a CSV file."""
		if not self.loader_thread_lock.acquire(False) or (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.FileChooser('Export Data', self.parent)
		file_name = self.config['campaign_name'] + '.csv'
		response = dialog.run_quick_save(file_name)
		dialog.destroy()
		if not response:
			self.loader_thread_lock.release()
			return
		destination_file = response['target_path']
		store = self.gobjects['treeview_campaign'].get_model()
		columns = dict(enumerate(('UID',) + self.view_columns))
		export.liststore_to_csv(store, destination_file, columns)
		self.loader_thread_lock.release()
Пример #13
0
 def signal_toolbutton_save_as(self, toolbutton):
     dialog = gui_utilities.FileChooser('Save HTML File', self.parent)
     html_file = self.config.get('mailer.html_file')
     if html_file:
         current_name = os.path.basename(html_file)
     else:
         current_name = 'message.html'
     response = dialog.run_quick_save(current_name=current_name)
     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
     self.toolbutton_save_html_file.set_sensitive(True)