<commit_before>ReportMaker = {
	title = 'Report Maker',
	icon = 'url(SyHybrid.scx#images\\16\\saverep.png)',
	default_template = 'Standard',
	default_template_sort = 'CVSS3',
	msg_nosession = 'You need to start a session before generating a report',
	session_name = '',
	session_dir = '',
	xmllist = '',
	template_action = '',
	template_name = '',
	template_sort = ''
}

function ReportMaker:can_open_report()
	local ui = self.ui
	return ui.openrep.value
end

function ReportMaker:do_tpl_item(name)
	local e = self.ui.element
	e:select('input[tplname="'..name..'"]')
	if self.template_action == 'get_default' then
		e.value=rm:getincludeitem(name)
	end
	if self.template_action == 'set_user' then
		rm:setincludeitem(name,e.value)
	end
end

function ReportMaker:do_template(action)
	self.template_action = action
	local ro = ctk.string.loop:new()
	ro:load(rm.IncludeList)
	while ro:parsing() do
	  self:do_tpl_item(ro.current)
    end
	ro:release()
end

function ReportMaker:set_template(name)
  require 'Repmaker'
	self.template_name = name
	rm = SyRepmaker:new()
	rm.Template = name
	self:do_template('get_default')
	rm:release()
end

function ReportMaker:set_templatesort(name)
	self.template_sort = name
end

function ReportMaker:gen_report()
    require 'SyMini'
    require 'Repmaker'
	rm = SyRepmaker:new()
	local ui = self.ui
	local filename = app.savefile(rm.Filter,'html',symini.info.sessionsdir..'Report_'..self.session_name)
	local reptitle = ui.report_title.value
	debug.print('file:'..filename)
	if filename ~= '' then
		rm.Filename = filename
		rm.SessionName = self.session_name
		rm.SessionDir = self.session_dir
		rm.Template = self.template_name
		rm.VulnSortMethod = self.template_sort
		self:do_template('set_user')
		if reptitle ~= '' then rm.ReportTitle = reptitle end
		tab.status = 'Generating report...'
		rm:savereport()
		debug.print('report saved')
		if self:can_open_report() then
			browser.newtab(filename)
			--browser.setactivepage('browser')
			--tab:gotourl(filename)
		end
		tab.status = ''
	end
	rm:release()
	debug.print('report maker released')
end

function ReportMaker:edit_sesfile(f)
	local ui = self.ui
	ui.editors:setattrib('xmlfile',f)
	ui.editors:setstyle('display','none')
	ui.vulneditor:setstyle('display','none')
	local xml = GXMLIniList:new()
	xml:loadfromfile(self.session_dir..f)
	type = xml:getvalue('type')
	ui.editorinclude.value = true
	if xml:getvalue('Include') == 'No' then<commit_msg>Improve open report after generation<commit_after>ReportMaker = {
	title = 'Report Maker',
	icon = 'url(SyHybrid.scx#images\\16\\saverep.png)',
	default_template = 'Standard',
	default_template_sort = 'CVSS3',
	msg_nosession = 'You need to start a session before generating a report',
	session_name = '',
	session_dir = '',
	xmllist = '',
	template_action = '',
	template_name = '',
	template_sort = ''
}

function ReportMaker:can_open_report()
	local ui = self.ui
	return ui.openrep.value
end

function ReportMaker:do_tpl_item(name)
	local e = self.ui.element
	e:select('input[tplname="'..name..'"]')
	if self.template_action == 'get_default' then
		e.value=rm:getincludeitem(name)
	end
	if self.template_action == 'set_user' then
		rm:setincludeitem(name,e.value)
	end
end

function ReportMaker:do_template(action)
	self.template_action = action
	local ro = ctk.string.loop:new()
	ro:load(rm.IncludeList)
	while ro:parsing() do
	  self:do_tpl_item(ro.current)
    end
	ro:release()
end

function ReportMaker:set_template(name)
  require 'Repmaker'
	self.template_name = name
	rm = SyRepmaker:new()
	rm.Template = name
	self:do_template('get_default')
	rm:release()
end

function ReportMaker:set_templatesort(name)
	self.template_sort = name
end

function ReportMaker:gen_report()
    require 'SyMini'
    require 'Repmaker'
	rm = SyRepmaker:new()
	local ui = self.ui
	local filename = app.savefile(rm.Filter,'html',symini.info.sessionsdir..'Report_'..self.session_name)
	local reptitle = ui.report_title.value
	debug.print('file:'..filename)
	if filename ~= '' then
		rm.Filename = filename
		rm.SessionName = self.session_name
		rm.SessionDir = self.session_dir
		rm.Template = self.template_name
		rm.VulnSortMethod = self.template_sort
		self:do_template('set_user')
		if reptitle ~= '' then rm.ReportTitle = reptitle end
		tab.status = 'Generating report...'
		rm:savereport()
		debug.print('report saved')
		if self:can_open_report() then
		    if rm.CanOpenInBrowser == true then
			  browser.newtab(filename)
			else
			  ctk.file.exec(filename)
			end
		end
		tab.status = ''
	end
	rm:release()
	debug.print('report maker released')
end

function ReportMaker:edit_sesfile(f)
	local ui = self.ui
	ui.editors:setattrib('xmlfile',f)
	ui.editors:setstyle('display','none')
	ui.vulneditor:setstyle('display','none')
	local xml = GXMLIniList:new()
	xml:loadfromfile(self.session_dir..f)
	type = xml:getvalue('type')
	ui.editorinclude.value = true
	if xml:getvalue('Include') == 'No' then
{'fraction_non_alphanumeric': 0.13350891410048624, 'fraction_numerical': 0.0012155591572123178, 'mean_word_length': 4.991504854368932, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 12}, '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': '4428795', 'n_tokens_mistral': 1824, 'n_tokens_neox': 1766, 'n_words': 338}