-
Notifications
You must be signed in to change notification settings - Fork 1
/
scan.cfm
91 lines (84 loc) · 4.5 KB
/
scan.cfm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<cfinclude template="config.cfm">
<cfsetting requesttimeout="900">
<cfoutput>
<cftry>
<cfif request.keyExists("fixinator_runner_config")>
<cfset config = request.fixinator_runner_config>
<cfelse>
<cfthrow message="Missing config">
</cfif>
<h2>Configuration</h2>
<p>Fixinator API Server: #encodeForHTML(config.fixinator_api_url)#</p>
<p>Report Format: #encodeForHTML(config.report_format)#</p>
<cfset fixinatorClient = new fixinatorclient.models.fixinator.FixinatorClient()>
<cfset fixinatorClient.setAPIURL(config.fixinator_api_url)>
<cfset fixinatorReport = new fixinatorclient.models.fixinator.FixinatorReport()>
<cfif config.keyExists("fixinator_api_key") AND len(config.fixinator_api_key)>
<cfset fixinatorClient.setAPIKey(config.fixinator_api_url)>
<cfelse>
<p><em>Fixinator API Key was not set (not defined in config), will use environment variables instead</em></p>
</cfif>
<cfif NOT ListFind("html,pdf",config.report_format)>
<cfthrow message="Invalid report_format, must be html or pdf">
</cfif>
<cfif NOT directoryExists(config.report_directory)>
<cfthrow message="The report_directory does not exist">
</cfif>
<cfcatch>
<cfoutput>
<p>❌ Error initializing FixinatorClient / FixinatorReport.</p>
<ul>
<li><cfif fileExists(ExpandPath("./fixinatorclient/models/fixinator/FixinatorClient.cfc"))>✅ FixinatorClient.cfc found<cfelse>❌ fixinatorclient/models/fixinator/FixinatorClient.cfc missing</cfif>
<li><cfif fileExists(ExpandPath("./fixinatorclient/models/fixinator/FixinatorReport.cfc"))>✅ FixinatorReport.cfc found<cfelse>❌ fixinatorclient/models/fixinator/FixinatorReport.cfc missing</cfif>
<li><cfif fileExists(ExpandPath("./fixinatorclient/mixins/generate-pdf.cfm"))>✅ generate-pdf.cfm found<cfelse>❌ fixinatorclient/mixins/generate-pdf.cfm missing</cfif>
</ul>
<p>#encodeForHTML(cfcatch.message)#</p>
<cfdump var="#cfcatch#">
<cfexit>
</cfoutput>
</cfcatch>
</cftry>
<h2>Applications</h2>
</cfoutput>
<cfif config.keyExists("applications") AND isArray(config.applications)>
<cfloop array="#config.applications#" index="app">
<cfoutput>
<h4>Scanning #encodeForHTML(app.name)#...</h4>
<cftry>
<cfif NOT directoryExists(app.path) OR fileExists(app.path)>
<cfthrow message="Invalid path for app: #app.path#">
</cfif>
<!--- run scan --->
<cfset result = fixinatorClient.run(path=app.path, config=app.fixinator_config)>
<cfif url.keyExists("dump_results") AND url.dump_results>
<cfdump var="#result#">
</cfif>
<!--- create report --->
<cfset reportFile = config.report_directory & "fixinator-#reReplace(lcase(app.name), "[^a-z0-9_-]", "", "ALL")#-#dateFormat(now(), "yyyy-mm-dd")#-#timeFormat(now(), "HH-mm")#.#lcase(config.report_format)#">
<cfset fixinatorReport.generateReport(format=config.report_format, resultFile=reportFile, data=result)>
<p>Created report file: #encodeForHTML(getFileFromPath(reportFile))#</p>
<cfif len(app.email_reports_to)>
<cfmail to="#app.email_reports_to#" from="#config.email_reports_from#" subject="Fixinator Scan: #app.name#" type="html">
<cfif config.report_format IS "html">
<cfoutput>#fileRead(reportFile)#</cfoutput>
<cfelse>
<p>PDF Report is Attached</p>
<!--- ignore:file-access --->
<cfmailparam file="#reportFile#" type="application/pdf">
</cfif>
</cfmail>
<p>Sent report to: #encodeForHTML(app.email_reports_to)#</p>
</cfif>
<p>✅ Finished #encodeForHTML(app.name)#</p>
<cfcatch type="any">
<p>❌ Error while scanning #encodeForHTML(app.name)#</p>
<p>#encodeForHTML(cfcatch.message)#</p>
<cfdump var="#cfcatch#">
</cfcatch>
</cftry>
<cftry><cfflush><cfcatch><!--- ignore flush error ---></cfcatch></cftry>
</cfoutput>
</cfloop>
<cfelse>
<p>No applications configured.</p>
</cfif>