<commit_before>import time
import os

import king_phisher.client.mailer as mailer
import king_phisher.client.plugins as plugins
import king_phisher.client.gui_utilities as gui_utilities

import jinja2.exceptions

try:
	from reportlab import platypus
	from reportlab.lib import styles
	from reportlab.lib.enums import TA_JUSTIFY
	from reportlab.lib.pagesizes import letter
	from reportlab.lib.units import inch
except ImportError:
	has_reportlab = False
else:
	has_reportlab = True

def _render_path(outfile, *joins, pathmod=os.path):
	outfile = pathmod.expandvars(outfile)
	outfile = pathmod.expanduser(outfile)
	outfile.join(outfile, *joins)
	return outfile

class Plugin(plugins.ClientPlugin):
	authors = ['<NAME>']
	title = 'Generate PDF'
	description = """
	Generates a PDF file with a link which includes the campaign URL with the
	individual message_id required to track individual visits to a website.
	Visit https://github.com/y4utj4/pdf_generator for example template files to
	use with this plugin.
	"""
	homepage = 'https://github.com/securestate/king-phisher-plugins'
	options = [
		plugins.ClientOptionString(
			'output_pdf',
			'pdf being generated',
			default='~/Attachment1.pdf',
			display_name='* Output PDF File'
		),
		plugins.ClientOptionString(
			'template_file',
			'Template file to read from',
			default='~/template.txt',
			display_name='* Template File'
		),
		plugins.ClientOptionString(
			'logo',
			'Image to include into the pdf',
			display_name='Logo / Inline Image'
		),
		plugins.ClientOptionString(
			'link_text',
			'Text for inserted link',
			default='Click here to accept',
			display_name='Link Text'
		)
	]
	req_min_version = '1.7.0b1'
	req_packages = {
		'reportlab': has_reportlab
	}
	def initialize(self):
		mailer_tab = self.application.main_tabs['mailer']
		self.text_insert = mailer_tab.tabs['send_messages'].text_insert
		self.add_menu_item('Tools > Create PDF Preview', self.make_preview)
		self.signal_connect('send-precheck', self.signal_send_precheck, gobject=mailer_tab)
		self.signal_connect('send-target', self.signal_send_target, gobject=mailer_tab)
		self.signal_connect('send-finished', self.signal_send_finished, gobject=mailer_tab)
		return True

	def signal_send_precheck(self, _):
		# file and option checks
		if not all((self.config['template_file'], self.config['output_pdf'], self.config['link_text'])):
			self.logger.debug('skipping exporting any attachments due to lack of information provided to run')
			return False
		if not os.path.isfile(self.config['template_file']):
			self.logger.error('template file does not exist, specify a valid template file')
			return False
		if self.config['logo'] and not os.path.isfile(self.config['template_file']):
			self.logger.error('specified template or logo file not found')
		self.logger.debug('pdf template file found, generating attachment')
		return True

	def make_preview(self, _):
		if not os.path.isfile(self.render_path(self.config['template_file'])):
			self.logger.error('template file does not exist, please review your options')
			gui_utilities.show_dialog_error(
				'File Error',
				self.application.get_active_window(),
				'Template file not found.'
			)
			return False

		outfile = self.render_path(self.config['output_pdf'])
		pdf_file = platypus.SimpleDocTemplate(outfile,
			pagesize=letter,
			rightMargin=72,
			leftMargin=72,
			topMargin=72,
			bottomMargin=18<commit_msg>made some syntax changes, gui dialogs, tested<commit_after>import time
import os

import king_phisher.client.mailer as mailer
import king_phisher.client.plugins as plugins
import king_phisher.client.gui_utilities as gui_utilities

import jinja2.exceptions

try:
	from reportlab import platypus
	from reportlab.lib import styles
	from reportlab.lib.enums import TA_JUSTIFY
	from reportlab.lib.pagesizes import letter
	from reportlab.lib.units import inch
except ImportError:
	has_reportlab = False
else:
	has_reportlab = True

def _render_path(outfile, *joins, pathmod=os.path):
	outfile = pathmod.expandvars(outfile)
	outfile = pathmod.expanduser(outfile)
	outfile.join(outfile, *joins)
	return outfile

class Plugin(plugins.ClientPlugin):
	authors = ['<NAME>']
	title = 'Generate PDF'
	description = """
	Generates a PDF file with a link which includes the campaign URL with the
	individual message_id required to track individual visits to a website.
	Visit https://github.com/y4utj4/pdf_generator for example template files to
	use with this plugin.
	"""
	homepage = 'https://github.com/securestate/king-phisher-plugins'
	options = [
		plugins.ClientOptionString(
			'output_pdf',
			'pdf being generated',
			default='~/Attachment1.pdf',
			display_name='* Output PDF File'
		),
		plugins.ClientOptionString(
			'template_file',
			'Template file to read from',
			default='~/template.txt',
			display_name='* Template File'
		),
		plugins.ClientOptionString(
			'logo',
			'Image to include into the pdf',
			display_name='Logo / Inline Image'
		),
		plugins.ClientOptionString(
			'link_text',
			'Text for inserted link',
			default='Click here to accept',
			display_name='Link Text'
		)
	]
	req_min_version = '1.7.0b1'
	req_packages = {
		'reportlab': has_reportlab
	}
	def initialize(self):
		mailer_tab = self.application.main_tabs['mailer']
		self.text_insert = mailer_tab.tabs['send_messages'].text_insert
		self.add_menu_item('Tools > Create PDF Preview', self.make_preview)
		self.signal_connect('send-precheck', self.signal_send_precheck, gobject=mailer_tab)
		self.signal_connect('send-target', self.signal_send_target, gobject=mailer_tab)
		self.signal_connect('send-finished', self.signal_send_finished, gobject=mailer_tab)
		return True

	def signal_send_precheck(self, _):
		# file and option checks
		if not all((self.config['template_file'], self.config['output_pdf'], self.config['link_text'])):
			self.logger.debug('skipping exporting any attachments due to lack of information provided to run')
			return False
		if not os.path.isfile(self.config['template_file']):
			self.logger.error('template file does not exist, specify a valid template file')
			gui_utilities.show_dialog_error(
				'File Error',
				self.application.get_active_window(),
				'Template file not found.'
			)
			return False
		self.logger.debug('pdf template file found, generating attachment')
		return True

	def make_preview(self, _):
		if not os.path.isfile(self.render_path(self.config['template_file'])):
			self.logger.error('template file does not exist, please review your options')
			gui_utilities.show_dialog_error(
				'File Error',
				self.application.get_active_window(),
				'Template file not found.'
			)
			return False

		outfile = self.render_path(self.config['output_pdf'])
		pdf_file = platypus.SimpleDocTemplate(outfile,
			pagesize=letter,
			rightMargin=72,
			leftMargin=72,
			topMargin=72,
			bottomMargin=18
{'fraction_non_alphanumeric': 0.10514802391716493, 'fraction_numerical': 0.004666763890914394, 'mean_word_length': 4.8968185726569216, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4375997', 'n_tokens_mistral': 2397, 'n_tokens_neox': 2177, 'n_words': 537}