Class: Vulnreport

Inherits:
Sinatra::Base
  • Object
show all
Defined in:
web.rb,
version.rb,
routes/test.rb,
routes/auth.rb,
routes/admin.rb,
routes/reports.rb,
routes/monitors.rb,
routes/application.rb

Overview

Copyright © 2016, salesforce.com, inc. All rights reserved. Licensed under the BSD 3-Clause license. For full license text, see LICENSE.txt file in the repo root or opensource.org/licenses/BSD-3-Clause

Defined Under Namespace

Modules: VERSION Classes: RequestDataExtractor

Instance Method Summary (collapse)

Instance Method Details

- (Object) /

Main index page - dashboard.

Web Route:

  • /

ERB File Used:

  • views/dash.erb



738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
# File 'web.rb', line 738

get '/' do
	@user = User.get(session[:uid])

	#What dash config are we using?
	if(@user.dashOverride >= 0)
		dcid = @user.dashOverride
	else
		if(!@user.verified?)
			dcid == 0
		else
			org = Organization.get(@user.org)
			if(org.nil?)
				dcid = 0
			else
				dcid = org.dashconfig
			end
		end
	end

	if(dcid > 0)
		dc = DashConfig.get(dcid)
		dcid == 0 if(dc.nil?)
	end

	instance_exec dcid, &show_dash
end

- (Date) endOfQuarter(d)

Given date, return end of FY quarter it falls in

Parameters:

  • d (DateTime)

    Date to find quarter for

Returns:

  • (Date)

    Last day of FY quarter that d falls in



174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'routes/reports.rb', line 174

def endOfQuarter(d)
	d = d.to_date
	if(d.month >= 2 && d.month <= 4)
		return Date.new(d.year, 4, 30)
	elsif(d.month >= 5 && d.month <= 7)
		return Date.new(d.year, 7, 31)
	elsif(d.month >= 8 && d.month <= 10)
		return Date.new(d.year, 10, 31)
	elsif(d.month == 11 || d.month == 12)
		return Date.new((d.year+1), 1, 31)
	elsif(d.month == 1)
		return Date.new(d.year, 1, 31)
	end
end

- (String) form_datestring(sd, ed)

Given the start date and end date in DateTime format, form a String representing the date period to pass in the URL to a report. This method is used on the POST route to create a URL to call the report via a GET route.

Parameters:

  • sd (DateTime)

    Start date of the period to report on

  • ed (DateTime)

    End date of the period to report on

Returns:

  • (String)

    String representing reporting period e.g. “03-01-2016…04-01-2016”



20
21
22
23
24
25
26
27
28
# File 'routes/reports.rb', line 20

def form_datestring(sd, ed)
	if((sd.nil? || ed.empty?) && (sd.nil? || ed.empty?))
		return "all"
	else
		startdate = DateTime.strptime(sd, '%m-%d-%Y').strftime('%m-%d-%Y')
		enddate = DateTime.strptime(ed, '%m-%d-%Y').strftime('%m-%d-%Y')
		return "#{startdate}...#{enddate}"
	end
end

- (String) form_flagstring(f, fall)

Given the App Flags param, form a string representing selected flags to pass in the URL to a report. This method is used on the POST route to create a URL to call the report via a GET route.

Parameters:

  • f (String)

    the selected flags from the report filter multiselect

  • fall (String)

    Value of the “all” option from flag multiselect (DEPRECATED)

Returns:

  • (String)

    String representing selected flags for the URL e.g. “all” or “1|3|4”



55
56
57
58
59
60
61
62
63
64
# File 'routes/reports.rb', line 55

def form_flagstring(f, fall)
	flagSelectAll = (!fall.nil? && fall.to_s.downcase == "all")
	if(flagSelectAll || f.nil? || f.empty?)
		flagStr = "all"
	else
		flagStr = f.join("|")
	end

	return flagStr
end

- (String) form_rtstring(rt, rtall)

Given the Record Type params, form a string representing selected RecordTypes to pass in the URL to a report. This method is used on the POST route to create a URL to call the report via a GET route. This method does NOT check permissions - see #parseRt

Parameters:

  • rt (String)

    Array of RecordType IDs

  • rtall (String)

    Value of the “all” report button representing all RTs

Returns:

  • (String)

    String representing selected record types for the URL e.g. “all” or “1|3|4”



37
38
39
40
41
42
43
44
45
46
# File 'routes/reports.rb', line 37

def form_rtstring(rt, rtall)
	rtSelectAll = (!rtall.nil? && rtall.to_s.downcase == "all")
	if(rtSelectAll || rt.nil? || rt.empty?)
		rtStr = "all"
	else
		rtStr = rt.join("|")
	end

	return rtStr
end

- (Integer) fy(d)

Given date, return FY it falls in

Parameters:

  • d (DateTime)

    Date to find FY for

Returns:

  • (Integer)

    FY number



210
211
212
213
214
215
216
217
# File 'routes/reports.rb', line 210

def fy(d)
	d = d.to_date
	if(d.month >= 2)
		return (d.year+1)
	else
		return d.year
	end
end

- (Object) GET '/'

Main index page - dashboard.

Web Route:

  • /

ERB File Used:

  • views/dash.erb



738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
# File 'web.rb', line 738

get '/' do
	@user = User.get(session[:uid])

	#What dash config are we using?
	if(@user.dashOverride >= 0)
		dcid = @user.dashOverride
	else
		if(!@user.verified?)
			dcid == 0
		else
			org = Organization.get(@user.org)
			if(org.nil?)
				dcid = 0
			else
				dcid = org.dashconfig
			end
		end
	end

	if(dcid > 0)
		dc = DashConfig.get(dcid)
		dcid == 0 if(dc.nil?)
	end

	instance_exec dcid, &show_dash
end

- (Object) GET '/admin/customVTs/?'



813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
# File 'routes/admin.rb', line 813

get '/admin/customVTs/?' do
	@customVTs = Array.new
	@counts = Array.new
	@firstUseVID = Array.new #First VID of use to look up later
	@usedTIDs = Array.new #array of arrays, uses of each
	downcased = Array.new

	Vulnerability.all(:vulntype => 0).each do |vt|
		if(!downcased.include?(vt.custom.downcase))
			@customVTs << vt.custom
			downcased = @customVTs.map(&:downcase)
			@counts << 1
			@firstUseVID << vt.id
			use = Array.new
			use << vt.test.id.to_s + "|" + vt.test.name + "|" + vt.test.application.name
			@usedTIDs << use
		else
			idx = downcased.index(vt.custom.downcase)
			@counts[idx] += 1
			@usedTIDs[idx] << vt.test.id.to_s + "|" + vt.test.name + "|" + vt.test.application.name
		end
	end

	erb :admin_vts_custom
end

- (Object) GET '/admin/dashConfigs/?'



1181
1182
1183
1184
1185
# File 'routes/admin.rb', line 1181

get '/admin/dashConfigs/?' do
	@dashConfigs = DashConfig.all()

	erb :admin_dcs
end

- (Object) GET '/admin/dashConfigs/:dcid/?'



1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
# File 'routes/admin.rb', line 1204

get '/admin/dashConfigs/:dcid/?' do
	dcid = params[:dcid].to_i

	@dc = DashConfig.get(dcid)
	if(@dc.nil?)
		@errstr = "Unable to find DashConfig"
		return erb :error
	end

	if(@dc.customCode)
		erb :admin_dc_single_cc
	else
		@rtOpts = RecordType.appRecordTypes()
		@nonRtTypes = NON_RT_DASHPANELS

		erb :admin_dc_single
	end
end

- (Object) GET '/admin/dashConfigs/:dcid/delete/?'



1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
# File 'routes/admin.rb', line 1293

get '/admin/dashConfigs/:dcid/delete/?' do
	dcid = params[:dcid].to_i

	@dc = DashConfig.get(dcid)
	if(@dc.nil?)
		@errstr = "Unable to find DashConfig"
		return erb :error
	end

	@dcOptions = DashConfig.all(:id.not => @dc.id)
	@orgs = Organization.all(:dashconfig => @dc.id)
	@users = User.all(:dashOverride => @dc.id)

	erb :admin_dc_delete_conf
end

- (Object) GET '/admin/dashConfigs/new/?'



1187
1188
1189
# File 'routes/admin.rb', line 1187

get '/admin/dashConfigs/new/?' do
	erb :admin_dc_new
end

- (Object) GET '/admin/exportFormats/?'



1092
1093
1094
1095
1096
# File 'routes/admin.rb', line 1092

get '/admin/exportFormats/?' do
	@exportFormats = ExportFormat.all()

	erb :admin_efs
end

- (Object) GET '/admin/exportFormats/:efid/?'



1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
# File 'routes/admin.rb', line 1123

get '/admin/exportFormats/:efid/?' do
	efid = params[:efid].to_i

	if(efid != 0)
		@ef = ExportFormat.get(efid)
		if(@ef.nil?)
			@errstr = "Unable to find ExportFormat"
			return erb :error
		end
		@default = false
	else
		@default = true
	end

	if(efid == 0)
		f = File.open("exportTemplates/default.erb", "rb")
	else
		f = File.open("exportTemplates/" + @ef.filename + ".erb", "rb")
	end

	@fileContents = f.read

	erb :admin_ef_single
end

- (Object) GET '/admin/exportFormats/new/?'



1098
1099
1100
# File 'routes/admin.rb', line 1098

get '/admin/exportFormats/new/?' do
	erb :admin_ef_new
end

- (Object) GET '/admin/flags/?'



1402
1403
1404
1405
1406
# File 'routes/admin.rb', line 1402

get '/admin/flags/?' do
	@flags = Flag.all()

	erb :admin_flags
end

- (Object) GET '/admin/flags/:fid/?'



1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
# File 'routes/admin.rb', line 1432

get '/admin/flags/:fid/?' do
	fid = params[:fid].to_i

	@flag = Flag.get(fid)
	if(@flag.nil?)
		@errstr = "Unable to find Flag"
		return erb :error
	end

	erb :admin_flag_single
end

- (Object) GET '/admin/flags/:fid/delete/?'



1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
# File 'routes/admin.rb', line 1474

get '/admin/flags/:fid/delete/?' do
	fid = params[:fid].to_i

	@flag = Flag.get(fid)
	if(@flag.nil?)
		@errstr = "Unable to find Flag"
		return erb :error
	end

	erb :admin_flag_delete_conf
end

- (Object) GET '/admin/flags/new/?'



1408
1409
1410
# File 'routes/admin.rb', line 1408

get '/admin/flags/new/?' do
	erb :admin_flag_new
end

- (Object) GET '/admin/orgs/?'



656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
# File 'routes/admin.rb', line 656

get '/admin/orgs/?' do
	@superOrgs = Array.new
	@regOrgs = Array.new
	@conOrgs = Array.new

	Organization.all().each do |o|
		if(o.super)
			@superOrgs << {:id => o.id, :name => o.name, :num => User.count(:org => o.id)}
			if(!o.contractor)
				@regOrgs << {:id => o.id, :name => o.name, :num => User.count(:org => o.id)}
			end
		else
			if(o.contractor)
				@conOrgs << {:id => o.id, :name => o.name, :num => User.count(:org => o.id)}
			else
				@regOrgs << {:id => o.id, :name => o.name, :num => User.count(:org => o.id)}
			end
		end
	end

	erb :admin_orgs
end

- (Object) GET '/admin/orgs/:oid/?'



459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
# File 'routes/admin.rb', line 459

get '/admin/orgs/:oid/?' do
	@org = Organization.get(params[:oid])
	@orgs = Organization.all()

	if(@org.nil?)
		@errstr = "Org not found"
		return erb :error 
	end

	@users = Array.new
	User.all(:org => @org.id).each do |u|
		status = "Active"
		if(!u.active)
			status = "Inactive"
		elsif(u.admin && u.org != 0)
			status = "Admin"
		elsif(u.reportsOnly && u.org != 0)
			status = "Reports Only"
		elsif(u.org == 0)
			status = "Unverified"
		end

		@users << {:uid => u.id, :name => u.name, :inits => u.initials, :status => status, :org => @org.name, :oid => @org.id, :email => u.email}
	end

	@appRecordTypes = RecordType.allAppRecordTypes()
	@allowedRTs = getAllowedRTsForOrg(@org.id)

	@dashConfigs = DashConfig.all(:active => true)

	erb :admin_org_single
end

- (Object) GET '/admin/orgs/:oid/delete/?'



578
579
580
581
582
583
584
585
586
587
588
589
# File 'routes/admin.rb', line 578

get '/admin/orgs/:oid/delete/?' do
	@org = Organization.get(params[:oid])
	if(@org.nil?)
		@errstr = "Org not found"
		return erb :error 
	end

	@orgOptions = Organization.all(:id.not => @org.id)
	@users = User.all(:org => @org.id)

	erb :admin_org_delete_conf
end

- (Object) GET '/admin/orgs/new/?'



435
436
437
# File 'routes/admin.rb', line 435

get '/admin/orgs/new/?' do
	erb :admin_org_new
end

- (Object) GET '/admin/recordTypes/?'



934
935
936
937
938
# File 'routes/admin.rb', line 934

get '/admin/recordTypes/?' do
	@appRecordTypes = RecordType.all(:object => LINK_TYPE::APPLICATION)

	erb :admin_rts
end

- (Object) GET '/admin/recordTypes/:rtid/?'



982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
# File 'routes/admin.rb', line 982

get '/admin/recordTypes/:rtid/?' do
	rtid = params[:rtid].to_i

	@rt = RecordType.get(rtid)
	if(@rt.nil?)
		@errstr = "Unable to find RecordType"
		return erb :error
	end

	@exportFormats = ExportFormat.all()

	@regOrgs = Organization.all(:contractor => false)
	@conOrgs = Organization.all(:contractor => true)
	@orgsAllowed = getOrgsAllowedForRT(@rt.id)
	@linkOptions = Array.new
	VRLinkedObject.each do |vrlo|
		@linkOptions << {:name => vrlo.vrlo_name.to_s, :key => vrlo.vrlo_key.to_s}
	end
	
	@vulnTypes = VulnType.all(:enabled => true).sort{ |x,y| x.name <=> y.name}
	@enabledVTs = Array.new
	VulnType.getByRecordType(rtid).each do |vt|
		@enabledVTs << vt.id
	end

	erb :admin_rt_single
end

- (Object) GET '/admin/recordTypes/new/?'



940
941
942
943
944
945
946
947
# File 'routes/admin.rb', line 940

get '/admin/recordTypes/new/?' do
	@linkOptions = Array.new
	VRLinkedObject.each do |vrlo|
		@linkOptions << {:name => vrlo.vrlo_name.to_s, :key => vrlo.vrlo_key.to_s}
	end
	
	erb :admin_rt_new
end

- (Object) GET '/admin/settings/?'



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'routes/admin.rb', line 98

get '/admin/settings/?' do
	@vr_name = getSetting('VR_INS_NAME')
	@vr_root = getSetting('VR_ROOT')
	@vr_footer = getSetting('VR_FOOTER')
	@sshotMaxSize = getSetting('SSHOT_MAX_SIZE_KB')
	@payloadMaxSize = getSetting('PAYLOAD_MAX_SIZE_KB')
	@pdf_on = (getSetting('PDF_EXPORT_ON') == 'true')

	@sso_auth = (getSetting('AUTH_SSO_ENABLED') == 'true')
	@autoadd = (getSetting('AUTO_ADD_USERS') == 'true')
	@sso_name = getSetting('AUTH_SSO_NAME')
	@sso_issuer = getSetting('AUTH_SSO_ISSUER')
	@sso_target_url = getSetting('AUTH_SSO_TARGET_URL')
	@sso_cert_fingerprint = getSetting('AUTH_SSO_CERT_FINGERPRINT')

	@login_auth = (getSetting('AUTH_LOGIN_ENABLED') == 'true')
	@login_pwlen = getSetting('AUTH_LOGIN_PWLEN')
			
	@app_version = Vulnreport::VERSION::STRING
	@app_hostname = %x{hostname}

	erb :admin_vr_settings
end

- (Object) GET '/admin/settings/cache/?'



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'routes/admin.rb', line 19

get '/admin/settings/cache/?' do 
	@hits = getSetting("cache_hits").to_i + settings.redis.get("cache_hits").to_i
	@misses = getSetting("cache_misses").to_i + settings.redis.get("cache_misses").to_i

	if(@hits == 0 && @misses == 0)
		@pct = 0
	else
		@pct = (@hits.to_f/(@hits.to_f+@misses.to_f))
	end

	keys = settings.redis.keys
	@keysTTL = Array.new
	keys.each do |k|
		@keysTTL << {:key => k, :ttl => settings.redis.ttl(k)}
	end

	erb :admin_vr_cache_settings
end

- (Object) GET '/admin/settings/mail/?'



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'routes/admin.rb', line 38

get '/admin/settings/mail/?' do
	@vr_mail_method = getSetting('VR_MAIL_METHOD')
	@vr_from_email = getSetting('VR_NOREPLY_EMAIL')

	if(@vr_mail_method == 'custom')
		@vr_mail_addr = getSetting('VR_MAIL_ADDR')
		@vr_mail_port = getSetting('VR_MAIL_PORT').to_i
		@vr_mail_domain = getSetting('VR_MAIL_DOMAIN')
		@vr_mail_user = getSetting('VR_MAIL_USER')
		@vr_mail_pass = getSetting('VR_MAIL_PASS')
	end

	erb :admin_vr_mail_settings
end

- (Object) GET '/admin/users/?'



379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
# File 'routes/admin.rb', line 379

get '/admin/users/?' do
	@adminUsers = Array.new
	@conUsers = Array.new
	@activeUsers = Array.new
	@roUsers = Array.new
	@unverified = Array.new
	@inactive = Array.new

	User.all().each do |u|
		org = Organization.get(u.org) unless u.org == 0

		status = "Active"
		if(!u.active)
			status = "Inactive"
		elsif(u.admin && u.org != 0)
			status = "Admin"
		elsif(u.reportsOnly && u.org != 0)
			status = "Reports Only"
		elsif(u.org == 0)
			status = "Unverified"
		end

		if(!u.active)
			if(u.org == 0)
				@inactive << {:uid => u.id, :name => u.name, :inits => u.initials, :status => status, :org => "", :oid => 0, :email => u.email}
			else
				@inactive << {:uid => u.id, :name => u.name, :inits => u.initials, :status => status, :org => org.name, :oid => org.id, :email => u.email}
			end
		else
			if(u.admin && u.org != 0)
				@adminUsers << {:uid => u.id, :name => u.name, :inits => u.initials, :status => status, :org => org.name, :oid => org.id, :email => u.email}
			end

			if(u.org != 0)
				if(org.contractor)
					@conUsers << {:uid => u.id, :name => u.name, :inits => u.initials, :status => status, :org => org.name, :oid => org.id, :email => u.email}
				elsif(u.reportsOnly)
					@roUsers << {:uid => u.id, :name => u.name, :inits => u.initials, :status => status, :org => org.name, :oid => org.id, :email => u.email}
				else
					@activeUsers << {:uid => u.id, :name => u.name, :inits => u.initials, :status => status, :org => org.name, :oid => org.id, :email => u.email}
				end
			else
				@unverified << {:uid => u.id, :name => u.name, :inits => u.initials, :status => status, :email => u.email}
			end
		end
	end

	@adminUsers.sort!{|x,y| x[:name].split(" ").last <=> y[:name].split(" ").last }
	@conUsers.sort!{|x,y| x[:name].split(" ").last <=> y[:name].split(" ").last }
	@activeUsers.sort!{|x,y| x[:name].split(" ").last <=> y[:name].split(" ").last }
	@roUsers.sort!{|x,y| x[:name].split(" ").last <=> y[:name].split(" ").last }
	@inactive.sort!{|x,y| x[:name].split(" ").last <=> y[:name].split(" ").last }

	erb :admin_users
end

- (Object) GET '/admin/users/:uid/?'



242
243
244
245
246
247
248
249
250
251
252
# File 'routes/admin.rb', line 242

get '/admin/users/:uid/?' do
	@user = User.get(params[:uid])
	if(@user.nil?)
		@errstr = "User not found"
		return erb :error 
	end
	
	@orgs = Organization.all()

	erb :admin_user_single
end

- (Object) GET '/admin/users/new/?'



177
178
179
180
181
# File 'routes/admin.rb', line 177

get '/admin/users/new/?' do
	@orgs = Organization.all()

	erb :admin_user_new
end

- (Object) GET '/admin/vtids/?'



808
809
810
811
# File 'routes/admin.rb', line 808

get '/admin/vtids/?' do
	@vts = VulnType.all(:enabled => true, :order => [:id.asc])
	erb :admin_vtids
end

- (Object) GET '/admin/vulntypes/?'



802
803
804
805
806
# File 'routes/admin.rb', line 802

get '/admin/vulntypes/?' do
	@vulnTypes = VulnType.all()

	erb :admin_vts
end

- (Object) GET '/admin/vulntypes/:vtid/?'



719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
# File 'routes/admin.rb', line 719

get '/admin/vulntypes/:vtid/?' do
	@vt = VulnType.get(params[:vtid])
	if(@vt.nil?)
		@errstr = "Type not found"
		return erb :error 
	end

	@enabled = ""
	if(@vt.enabled)
		@enabled = "checked"
	end

	@appRecordTypes = RecordType.appRecordTypes()

	erb :admin_vt_single
end

- (Object) GET '/admin/vulntypes/new/?'



679
680
681
682
683
# File 'routes/admin.rb', line 679

get '/admin/vulntypes/new/?' do
	@appRecordTypes = RecordType.appRecordTypes()

	erb :admin_vt_new
end

- (Object) GET '/auditMonitors/?'



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
# File 'routes/monitors.rb', line 46

get '/auditMonitors/?' do
	halt 401, (erb :unauth) if(!canAuditMonitors?)

	if(MONITOR_EVENT_TYPES.size == 0)
		@noMonitorTypes = true
		@last = nil
		@next = nil
		@total = 0
		return erb :monitor_index
	end

	#Offset parse
	lim = 50

	if(params[:os].nil?)
		offset = 0
	else
		offset = params[:os].to_i
	end
	@total = AuditRecord.count(:event_type => MONITOR_EVENT_TYPES)

	@start = offset+1
	@end = (offset+lim > @total) ? @total : (offset+lim)

	@next = nil
	if(offset+lim < @total)
		@next = offset+lim
	end

	@last = nil
	if(offset > 0)
		@last = offset-lim
		if(@last < 0)
			@last = 0
		end
	end

	@mas = AuditRecord.all(:event_type => MONITOR_EVENT_TYPES, :order => [:event_at.desc], :limit => lim, :offset => offset)

	erb :monitor_index
end

- (Object) GET '/auditMonitors/:maid/?'



202
203
204
205
206
207
208
209
210
211
212
# File 'routes/monitors.rb', line 202

get '/auditMonitors/:maid/?' do
	halt 401, (erb :unauth) if(!canAuditMonitors?)

	@ma = AuditRecord.get(params[:maid].to_i)
	if(@ma.nil?)
		@errstr = "Monitor Alert Not Found"
		erb :error
	end

	erb :monitor_alert_single
end

- (Object) GET '/auditMonitors/:maid/flag/?'



181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'routes/monitors.rb', line 181

get '/auditMonitors/:maid/flag/?' do
	halt 401, (erb :unauth) if(!canAuditMonitors?)

	ma = AuditRecord.get(params[:maid].to_i)
	if(ma.nil?)
		return 404
	end

	ma.reviewed = true
	ma.reviewed_at = DateTime.now
	ma.reviewed_by = @session[:uid]
	ma.flagged = true
	if(ma.save)
		redirect "/auditMonitors/#{ma.id}"
	else
		Rollbar.error("Error saving AuditRecord object", {:monitorID => ma.id, :fault => ma.errors.to_s})
		@errstr = "Error marking AuditRecord as flagged"
		erb :error
	end
end

- (Object) GET '/auditMonitors/:maid/markReviewed/?'



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'routes/monitors.rb', line 142

get '/auditMonitors/:maid/markReviewed/?' do
	halt 401, (erb :unauth) if(!canAuditMonitors?)

	ma = AuditRecord.get(params[:maid].to_i)
	if(ma.nil?)
		return 404
	end

	ma.reviewed = true
	ma.reviewed_at = DateTime.now
	ma.reviewed_by = @session[:uid]
	if(ma.save)
		redirect "/auditMonitors/#{ma.id}"
	else
		Rollbar.error("Error saving AuditRecord object", {:monitorID => ma.id, :fault => ma.errors.to_s})
		@errstr = "Error marking AuditRecord as reviewed"
		erb :error
	end
end

- (Object) GET '/auditMonitors/:maid/reopen/?'



162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'routes/monitors.rb', line 162

get '/auditMonitors/:maid/reopen/?' do
	halt 401, (erb :unauth) if(!canAuditMonitors?)

	ma = AuditRecord.get(params[:maid].to_i)
	if(ma.nil?)
		return 404
	end

	ma.reviewed = false
	ma.flagged = false
	if(ma.save)
		redirect "/auditMonitors/#{ma.id}"
	else
		Rollbar.error("Error saving AuditRecord object", {:monitorID => ma.id, :fault => ma.errors.to_s})
		@errstr = "Error marking AuditRecord as reopened"
		erb :error
	end
end

- (Object) GET '/confirmAlloc'



1241
1242
1243
1244
1245
# File 'web.rb', line 1241

get '/confirmAlloc' do
	a = MonthlyAllocation.allocationForUser(session[:uid])
	a.update(:wasAutoSet => false)
	redirect "/"
end

- (Object) GET '/help'



1254
1255
1256
# File 'web.rb', line 1254

get '/help' do
	redirect "http://vulnreport.io/documentation"
end

- (Object) GET '/login/?'



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
# File 'routes/auth.rb', line 25

get '/login/?' do
	if(!session[:login_error].nil?)
		@login_error = true
		@login_error_str = session[:login_error]
		session[:login_error] = nil
	elsif(session[:logout_complete])
		@logout_success = true
		session.clear
	end

	seeded = getSetting('VR_SEEDED')
	if(seeded.nil? || seeded != 'true')
		@login_error = true
		@login_error_str = "Vulnreport has not been seeded"
		@login_auth = true
	else		
		@login_auth = (getSetting('AUTH_LOGIN_ENABLED') == 'true')
		redirect "/saml/login" if (!@login_auth && session[:login_error].nil? && !@logout_success)

		@sso_auth = (getSetting('AUTH_SSO_ENABLED') == 'true')
		if(@sso_auth)
			@sso_name = getSetting('AUTH_SSO_NAME').strip
			@sso_name = "SSO" if(@sso_name.nil? || @sso_name.empty?)
		end
	end
		
	erb :auth_login
end

- (Object) GET '/remoteBH/:q/?'

Bloodhound remote search endpoint. If string in search bar is not found in local (prefetch) data additional results will come from this endpoint.

Web Route:

  • /remoteBH/[SEARCH STRING]



1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
# File 'web.rb', line 1173

get '/remoteBH/:q/?' do
	q = params[:q]

	if(reports_only?)
		return "[]"
	end

	allowedRTs = getAllowedRTsForUser(@session[:uid])
	apps = Array.new

	Application.all(:record_type => allowedRTs, :order => [ :id.desc ], :name.like => "%#{q}%", :limit => 250).each do |a|
		if(a.isPrivate)
			next if(!a.allow_UIDs.nil? && !a.allow_UIDs.include?(@session[:uid]))
		end
		apps << {"name" => a.name, :id => a.id}.to_json
	end

	return "[#{apps.join(",")}]"
end

- (Object) GET '/reports/?'

Index #



2192
2193
2194
2195
2196
2197
2198
# File 'routes/reports.rb', line 2192

get '/reports/?' do
	if(reports_only?)
		erb :reports_index_reporters
	else
		erb :reports_index
	end
end

- (Object) GET '/reports/alloc/:month/:year/?'

Allocation - Current #



1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
# File 'routes/reports.rb', line 1855

get '/reports/alloc/:month/:year/?' do
	@users = User.all(:useAllocation => true)
	@totalReviewsAllocated = 0
	@totalReviewsActual = 0
	@totalTestsActual = 0

	@data = Hash.new

	yr = params[:year].to_i
	month = params[:month].to_i

	if(yr < 2014 || yr > 2020 || month < 1 || month > 12)
		@startDate = Date.today.at_beginning_of_month
	else
		@startDate = Date.new(yr, month, 1)
	end
	endDate = @startDate >> 1

	MonthlyAllocation.all(:month => month, :year => yr).each do |ma|
		found = false
		@users.each do |u|
			found = true if(u.id == ma.uid)
		end

		@users << User.get(ma.uid) if !found
	end

	@users.each do |u|
		a = MonthlyAllocation.allocationForUser(u.id, month=@startDate.month, year=@startDate.year)
		if a.nil?
			a = 0
			allocNil = true
			autoSet = false
		else
			autoSet = a.wasAutoSet
			a = a.allocation
			allocNil = false
		end
		allocPct = a
		allocApps = (((u.allocCoeff.to_f)/12.0)*(a.to_f/100.0))
		@totalReviewsAllocated += allocApps.round

		testsThisReviewer = 0
		appsThisReviewer = Array.new
		Test.all(:reviewer => u.id, :complete => true, :closed_at => (@startDate..endDate)).each do |t|
			testsThisReviewer += 1
			if(!appsThisReviewer.include?(t.application_id))
				appsThisReviewer << t.application_id
			end
		end

		@data[u.id] = {:allocNil => allocNil, :auto => autoSet, :allocPct => allocPct, :allocApps => allocApps, :apps => appsThisReviewer, :numTests => testsThisReviewer}
		@totalReviewsActual += appsThisReviewer.length
		@totalTestsActual += testsThisReviewer
	end

	@totalReviewsAllocated = @totalReviewsAllocated

	erb :reports/allocThisMonth"
end

- (Object) GET '/reports/alloc/allocVTests/?'



2166
2167
2168
# File 'routes/reports.rb', line 2166

get '/reports/alloc/allocVTests/?' do
	redirect "/reports/alloc/allocVTests/total/default/month"
end

- (Object) GET '/reports/alloc/allocVTests/:rid/:period/:interval/?'

Allocation v Apps (Total or User) #



2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
# File 'routes/reports.rb', line 2053

get '/reports/alloc/allocVTests/:rid/:period/:interval/?' do
	@formsub = "/reports/alloc/allocVTests"
	@intervals = ["Month"]
	
	if(params[:rid] == "total" || params[:rid] == "0")
		rid = 0
		@reviewer = User.new(:id => 0, :name => "Total")
	else
		rid = params[:rid].to_i
		@reviewer = User.get(rid)
		if(@reviewer.nil?)
			@errstr = "User not found"
			return erb :error
		end
	end
	
	@int, @intString = parseInterval(params[:interval].downcase, @intervals)
	@startdate, @enddate, @periodString = parsePeriod(params[:period].downcase)

	@reviewers = Array.new
	addedToRev = Array.new
	User.all().each do |u|
		next if u.name.nil?
		next if(addedToRev.include?(u.name.downcase))
		@reviewers << {:id => u.id, :name => u.name}
		addedToRev << u.name.downcase
	end

	@labels = Array.new
	@data_alloc = Array.new
	@data_actual = Array.new
	
	if(@int == "month")
		date = Date.new(@startdate.year, @startdate.month, 1)
		while date < @enddate do
			@labels << date.strftime('%B, %Y')
			
			if(rid == 0)
				@users = User.all(:useAllocation => true)
				MonthlyAllocation.all(:month => date.month, :year => date.year).each do |ma|
					found = false
					@users.each do |u|
						found = true if(u.id == ma.uid)
					end

					@users << User.get(ma.uid) if !found
				end

				totalReviewsAllocated = 0
				totalReviewsActual = 0

				@users.each do |u|
					a = MonthlyAllocation.allocationForUser(u.id, date.month, date.year)
					if a.nil?
						a = 0
					else
						a = a.allocation
					end
					totalReviewsAllocated += (((u.allocCoeff.to_f)/12.0)*(a.to_f/100.0)).round

					testsThisReviewer = 0
					appsThisReviewer = Array.new
					Test.all(:reviewer => u.id, :complete => true, :closed_at => (date..(date.end_of_month).to_datetime.end_of_day)).each do |t|
						testsThisReviewer += 1
						if(!appsThisReviewer.include?(t.application_id))
							appsThisReviewer << t.application_id
						end
					end
					totalReviewsActual += appsThisReviewer.length
				end
				@data_alloc << totalReviewsAllocated
				@data_actual << totalReviewsActual
			else
				alloc = MonthlyAllocation.allocationForUser(rid, date.month, date.year)
				if alloc.nil?
					alloc = 0
				else
					alloc = alloc.allocation
				end

				allocPct = alloc
				allocApps = (((@reviewer.allocCoeff.to_f)/12.0)*(alloc.to_f/100.0)).round

				thisTests = 0
				thisApps = Array.new
				Test.all(:reviewer => rid, :complete => true, :closed_at => (date..(date.end_of_month).to_datetime.end_of_day)).each do |t|
					thisTests += 1
					if(!thisApps.include?(t.application_id))
						thisApps << t.application_id
					end
				end

				@data_alloc << allocApps
				@data_actual << thisApps.length
			end

			date = (date >> 1)
		end
	end

	@rangeTotalAllocated = @data_alloc.inject(0, :+)
	@rangeTotalActual = @data_actual.inject(0, :+)

	erb :reports/allocVTests"
end

- (Object) GET '/reports/alloc/thisMonth/?'



1916
1917
1918
1919
# File 'routes/reports.rb', line 1916

get '/reports/alloc/thisMonth/?' do
	d = Date.today.at_beginning_of_month
	redirect "/reports/alloc/#{d.month}/#{d.year}"
end

- (Object) GET '/reports/alloc/userHistorical/?'



2045
2046
2047
# File 'routes/reports.rb', line 2045

get '/reports/alloc/userHistorical/?' do
	redirect "/reports/alloc/userHistorical/default/month"
end

- (Object) GET '/reports/alloc/userHistorical/:period/:interval/?'

Historical Allocation #



1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
# File 'routes/reports.rb', line 1925

get '/reports/alloc/userHistorical/:period/:interval/?' do
	@formsub = "/reports/alloc/userHistorical"
	@intervals = ["Month", "Quarter", "Year"]
	
	@int, @intString = parseInterval(params[:interval].downcase, @intervals)
	@startdate, @enddate, @periodString = parsePeriod(params[:period].downcase)
	
	@datasets_pct = Hash.new
	@datasets_rev = Hash.new
	@datasets_rev["All"] = Array.new

	User.all(:useAllocation => true).each do |u|
		@datasets_pct[u.name] = Array.new
		@datasets_rev[u.name] = Array.new
	end

	@labels = Array.new
	
	if(@int == "month")
		date = Date.new(@startdate.year, @startdate.month, 1)
		while date < @enddate do
			@labels << date.strftime('%B, %Y')
			allcount = 0
			
			User.all(:useAllocation => true).each do |u|
				alloc = MonthlyAllocation.allocationForUser(u.id, date.month, date.year)
				if(alloc.nil?)
					alloc = 0 
				else
					alloc = alloc.allocation
				end

				@datasets_pct[u.name] << alloc
				@datasets_rev[u.name] << (((u.allocCoeff.to_f)/12.0)*(alloc.to_f/100.0)).round
				allcount += (((u.allocCoeff.to_f)/12.0)*(alloc.to_f/100.0))
			end

			@datasets_rev["All"] << allcount.round

			date = (date >> 1)
		end
	elsif(@int == "quarter")
		first = (startOfQuarter(@startdate) < @startdate) ? @startdate : startOfQuarter(@startdate)
		last = (endOfQuarter(@startdate) > @enddate) ? @enddate : endOfQuarter(@startdate)
		while first < @enddate do
			@labels << "Q" + qnum(first).to_s + ", FY " + fy(first).to_s
			allcount = 0
			
			User.all(:useAllocation => true).each do |u|
				alloc = 0
				curDate = first
				while(curDate.month <= last.month)
					thisAlloc = MonthlyAllocation.allocationForUser(u.id, date.month, date.year)
					if(thisAlloc.nil?)
						alloc += 0 
					else
						alloc += thisAlloc
					end

					curDate >> 1
				end

				alloc = (alloc/3).round(1)

				@datasets_pct[u.name] << alloc
				@datasets_rev[u.name] << (((u.allocCoeff.to_f)/12.0)*(alloc.to_f/100.0)).round
				allcount += (((u.allocCoeff.to_f)/12.0)*(alloc.to_f/100.0))
			end

			@datasets_rev["All"] << allcount.round
			
			first = startOfQuarter(first >> 3)
			last = (endOfQuarter(first) > @enddate) ? @enddate : endOfQuarter(first)
		end
	elsif(@int == "year")
		first = @startdate.to_date
		last = Date.new(first.year, 12, 31)
		last = @enddate if @enddate < last
		while first < @enddate do
			@labels << first.strftime('%Y')
			allcount = 0
			
			User.all(:useAllocation => true).each do |u|
				alloc = 0
				curDate = first
				while(curDate.month <= last.month)
					thisAlloc = MonthlyAllocation.allocationForUser(u.id, date.month, date.year)
					if(thisAlloc.nil?)
						alloc += 0 
					else
						alloc += thisAlloc
					end

					curDate >> 1
				end

				alloc = (alloc/3).round(1)

				@datasets_pct[u.name] << alloc
				@datasets_rev[u.name] << (((u.allocCoeff.to_f)/12.0)*(alloc.to_f/100.0)).round
				allcount += (((u.allocCoeff.to_f)/12.0)*(alloc.to_f/100.0))
			end

			@datasets_rev["All"] << allcount.round
			
			first = Date.new((first.year+1), 1, 1)
			last = Date.new(first.year, 12, 31)
			last = @enddate.to_date if @enddate < last
		end
	end

	erb :reports/histAllocation"
end

- (Object) GET '/reports/reviewer/statsByOrg/?'



1374
1375
1376
# File 'routes/reports.rb', line 1374

get '/reports/reviewer/statsByOrg/?' do
	redirect "/reports/reviewer/statsByOrg/#{session[:org]}/default/month/all/all"
end

- (Object) GET '/reports/reviewer/statsByOrg/:oid/:period/:interval/:flags/:rt/?'

Stats by Organization #



1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
# File 'routes/reports.rb', line 1243

get '/reports/reviewer/statsByOrg/:oid/:period/:interval/:flags/:rt/?' do
	@formsub = "/reports/reviewer/statsByOrg"
	@intervals = ["Day", "Week", "Month", "Quarter", "Year"]
	
	oid = params[:oid].to_i
	@org = Organization.get(oid)
	if(@org.nil?)
		@errstr = "Organization not found"
		return erb :error
	end
	
	@int, @intString = parseInterval(params[:interval].downcase, @intervals)
	@startdate, @enddate, @periodString = parsePeriod(params[:period].downcase)
	@selectedFlags, @appTypeString = parseFlags(params[:flags])
	@selectedRecordTypes = parseRt(params[:rt])

	@orgs = Array.new
	addedToRev = Array.new
	Organization.all().each do |o|
		next if(addedToRev.include?(o.name.downcase))
		@orgs << {:id => o.id, :name => o.name}
		addedToRev << o.name.downcase
	end

	@labels = Array.new
	@testCounts = Array.new
	@testSum = Array.new
	@vulnCounts = Array.new
	@vulnSum = Array.new

	if(@int == "day")
		@startdate.upto(@enddate) do |date|
			@labels << date.strftime('%m-%d-%Y')
			vct = 0
			tct = 0
			Test.allWithFlags(@selectedFlags, :org_created => oid, :complete => true, :closed_at => (date..date+1), Test.application.record_type => @selectedRecordTypes).each do |t|
				tct += 1
				vct += Vulnerability.count(:test_id => t.id, :created_at => (date..date+1))
			end
			@testCounts << tct
			@testSum << @testCounts.inject(0, :+)
			@vulnCounts << vct
			@vulnSum << @vulnCounts.inject(0, :+)
		end
	elsif(@int == "week")
		@startdate.step(@enddate, 7) do |date|
			@labels << date.strftime('%m-%d-%Y')
			vct = 0
			tct = 0
			Test.allWithFlags(@selectedFlags, :org_created => oid, :complete => true, :closed_at => (date..date+7), Test.application.record_type => @selectedRecordTypes).each do |t|
				tct += 1
				vct += Vulnerability.count(:test_id => t.id, :created_at => (date..date+7))
			end
			@testCounts << tct
			@testSum << @testCounts.inject(0, :+)
			@vulnCounts << vct
			@vulnSum << @vulnCounts.inject(0, :+)
		end
	elsif(@int == "month")
		date = Date.new(@startdate.year, @startdate.month, 1)
		while date < @enddate do
			@labels << date.strftime('%B, %Y')
			vct = 0
			tct = 0
			Test.allWithFlags(@selectedFlags, :org_created => oid, :complete => true, :closed_at => (date..(date.end_of_month).to_datetime.end_of_day), Test.application.record_type => @selectedRecordTypes).each do |t|
				tct += 1
				vct += Vulnerability.count(:test_id => t.id, :created_at => (date..(date.end_of_month).to_datetime.end_of_day))
			end
			@testCounts << tct
			@testSum << @testCounts.inject(0, :+)
			@vulnCounts << vct
			@vulnSum << @vulnCounts.inject(0, :+)
			date = (date >> 1)
		end
	elsif(@int == "quarter")
		first = (startOfQuarter(@startdate) < @startdate) ? @startdate : startOfQuarter(@startdate)
		last = (endOfQuarter(@startdate) > @enddate) ? @enddate : endOfQuarter(@startdate)
		while first < @enddate do
			@labels << "Q" + qnum(first).to_s + ", FY " + fy(first).to_s
			vct = 0
			tct = 0
			Test.allWithFlags(@selectedFlags, :org_created => oid, :complete => true, :closed_at => ((first.to_datetime)...(last.to_datetime.end_of_day)), Test.application.record_type => @selectedRecordTypes).each do |t|
				tct += 1
				vct += Vulnerability.count(:test_id => t.id, :created_at => ((first.to_datetime)...(last.to_datetime.end_of_day)))
			end
			@testCounts << tct
			@testSum << @testCounts.inject(0, :+)
			@vulnCounts << vct
			@vulnSum << @vulnCounts.inject(0, :+)
			first = startOfQuarter(first >> 3)
			last = (endOfQuarter(first) > @enddate) ? @enddate : endOfQuarter(first)
		end
	elsif(@int == "year")
		first = @startdate.to_date
		last = Date.new(first.year, 12, 31)
		last = @enddate if @enddate < last
		while first < @enddate do
			@labels << first.strftime('%Y')
			vct = 0
			tct = 0
			Test.allWithFlags(@selectedFlags, :org_created => oid, :complete => true, :closed_at => ((first.to_datetime)...(last.to_datetime.end_of_day)), Test.application.record_type => @selectedRecordTypes).each do |t|
				tct += 1
				vct += Vulnerability.count(:test_id => t.id, :created_at => ((first.to_datetime)...(last.to_datetime.end_of_day)))
			end
			@testCounts << tct
			@testSum << @testCounts.inject(0, :+)
			@vulnCounts << vct
			@vulnSum << @vulnCounts.inject(0, :+)
			first = Date.new((first.year+1), 1, 1)
			last = Date.new(first.year, 12, 31)
			last = @enddate.to_date if @enddate < last
		end
	end

	@totalTests = @testCounts.inject(0, :+)
	@totalVulns = @vulnCounts.inject(0, :+)
	@testsInProg = Test.countWithFlags(@selectedFlags, :org_created => oid, :complete => false, Test.application.record_type => @selectedRecordTypes)

	erb :reports/statsByOrg"
end

- (Object) GET '/reports/reviewer/statsByReviewer/?'



1235
1236
1237
# File 'routes/reports.rb', line 1235

get '/reports/reviewer/statsByReviewer/?' do
	redirect "/reports/reviewer/statsByReviewer/#{session[:uid]}/default/month/all/all"
end

- (Object) GET '/reports/reviewer/statsByReviewer/:rid/:period/:interval/:flags/:rt/?'

Stats by Reviewer #



1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
# File 'routes/reports.rb', line 1083

get '/reports/reviewer/statsByReviewer/:rid/:period/:interval/:flags/:rt/?' do
	@formsub = "/reports/reviewer/statsByReviewer"
	@intervals = ["Day", "Week", "Month", "Quarter", "Year"]
	
	rid = params[:rid].to_i
	@reviewer = User.get(rid)
	if(@reviewer.nil?)
		@errstr = "User not found"
		return erb :error
	end
	
	@int, @intString = parseInterval(params[:interval].downcase, @intervals)
	@startdate, @enddate, @periodString = parsePeriod(params[:period].downcase)
	@selectedFlags, @appTypeString = parseFlags(params[:flags])
	@selectedRecordTypes = parseRt(params[:rt])

	@reviewers = Array.new
	addedToRev = Array.new
	User.all().each do |u|
		next if u.name.nil?
		next if(addedToRev.include?(u.name.downcase))
		@reviewers << {:id => u.id, :name => u.name}
		addedToRev << u.name.downcase
	end

	@labels = Array.new
	@testCounts = Array.new
	@testSum = Array.new
	@vulnCounts = Array.new
	@vulnSum = Array.new

	if(@int == "day")
		@startdate.upto(@enddate) do |date|
			@labels << date.strftime('%m-%d-%Y')
			vct = 0
			tct = 0
			Test.allWithFlags(@selectedFlags, :reviewer => rid, :complete => true, :closed_at => (date..date+1), Test.application.record_type => @selectedRecordTypes).each do |t|
				tct += 1
				vct += t.vulnerabilities.size
			end
			@testCounts << tct
			@testSum << @testCounts.inject(0, :+)
			@vulnCounts << vct
			@vulnSum << @vulnCounts.inject(0, :+)
		end
	elsif(@int == "week")
		@startdate.step(@enddate, 7) do |date|
			@labels << date.strftime('%m-%d-%Y')
			vct = 0
			tct = 0
			Test.allWithFlags(@selectedFlags, :reviewer => rid, :complete => true, :closed_at => (date..date+7), Test.application.record_type => @selectedRecordTypes).each do |t|
				tct += 1
				vct += t.vulnerabilities.size
			end
			@testCounts << tct
			@testSum << @testCounts.inject(0, :+)
			@vulnCounts << vct
			@vulnSum << @vulnCounts.inject(0, :+)
		end
	elsif(@int == "month")
		date = Date.new(@startdate.year, @startdate.month, 1)
		while date < @enddate do
			@labels << date.strftime('%B, %Y')
			vct = 0
			tct = 0
			Test.allWithFlags(@selectedFlags, :reviewer => rid, :complete => true, :closed_at => (date..(date.end_of_month).to_datetime.end_of_day), Test.application.record_type => @selectedRecordTypes).each do |t|
				tct += 1
				vct += t.vulnerabilities.size
			end
			@testCounts << tct
			@testSum << @testCounts.inject(0, :+)
			@vulnCounts << vct
			@vulnSum << @vulnCounts.inject(0, :+)
			date = (date >> 1)
		end
	elsif(@int == "quarter")
		first = (startOfQuarter(@startdate) < @startdate) ? @startdate : startOfQuarter(@startdate)
		last = (endOfQuarter(@startdate) > @enddate) ? @enddate : endOfQuarter(@startdate)
		while first < @enddate do
			@labels << "Q" + qnum(first).to_s + ", FY " + fy(first).to_s
			vct = 0
			tct = 0
			Test.allWithFlags(@selectedFlags, :reviewer => rid, :complete => true, :closed_at => ((first.to_datetime)...(last.to_datetime.end_of_day)), Test.application.record_type => @selectedRecordTypes).each do |t|
				tct += 1
				vct += t.vulnerabilities.size
			end
			@testCounts << tct
			@testSum << @testCounts.inject(0, :+)
			@vulnCounts << vct
			@vulnSum << @vulnCounts.inject(0, :+)
			first = startOfQuarter(first >> 3)
			last = (endOfQuarter(first) > @enddate) ? @enddate : endOfQuarter(first)
		end
	elsif(@int == "year")
		first = @startdate.to_date
		last = Date.new(first.year, 12, 31)
		last = @enddate if @enddate < last
		while first < @enddate do
			@labels << first.strftime('%Y')
			vct = 0
			tct = 0
			Test.allWithFlags(@selectedFlags, :reviewer => rid, :complete => true, :closed_at => ((first.to_datetime)...(last.to_datetime.end_of_day)), Test.application.record_type => @selectedRecordTypes).each do |t|
				tct += 1
				vct += t.vulnerabilities.size
			end
			@testCounts << tct
			@testSum << @testCounts.inject(0, :+)
			@vulnCounts << vct
			@vulnSum << @vulnCounts.inject(0, :+)
			first = Date.new((first.year+1), 1, 1)
			last = Date.new(first.year, 12, 31)
			last = @enddate.to_date if @enddate < last
		end
	end

	@totalTests = @testCounts.inject(0, :+)
	@totalVulns = @vulnCounts.inject(0, :+)
	@testsInProg = Test.count(:reviewer => rid, :complete => false)

	@activeReviews = Array.new
	@pastReviews = Array.new
	addedReviews = Array.new
	
	Test.allWithFlags(@selectedFlags, :complete => false, :reviewer => rid, :order => [ :id.asc ], :created_at => (@startdate..@enddate), Test.application.record_type => @selectedRecordTypes).each do |t|
		next if(addedReviews.include?(t.application_id))
		next if(!canViewReview?(t.application_id))

		@activeReviews << {:app => Application.get(t.application_id), :test => t}
		addedReviews << t.application_id
	end

	Test.allWithFlags(@selectedFlags, :complete => true, :reviewer => rid, :order => [ :id.desc ], :created_at => (@startdate..@enddate), Test.application.record_type => @selectedRecordTypes).each do |t|
		next if(addedReviews.include?(t.application_id))
		next if(!canViewReview?(t.application_id))

		@pastReviews << {:app => Application.get(t.application_id), :test => t}
		addedReviews << t.application_id
	end

	erb :reports/statsByReviewer"
end

- (Object) GET '/reports/sys/dash/?'

Sys Dash #



2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
# File 'routes/reports.rb', line 2174

get '/reports/sys/dash/?' do
	@numApps = Application.count()
	@numTests = Test.count()
	@numVulns = Vulnerability.count()
	@numFlags = ApplicationFlag.count()
	@numUsers = User.count()
	@numOrgs = Organization.count()
	@numComments = Comment.count()
	@numNotifications = Notification.count()
	@auditCount = AuditRecord.count()

	erb :reports/sysdash"
end

- (Object) GET '/reports/tests/disagreements/?'



245
246
247
# File 'routes/reports.rb', line 245

get '/reports/tests/disagreements/?' do
	redirect "/reports/tests/disagreements/default/all"
end

- (Object) GET '/reports/tests/disagreements/:period/:flags/?'

Approval Flow Disagreements #



223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# File 'routes/reports.rb', line 223

get '/reports/tests/disagreements/:period/:flags/?' do
	@formsub = "/reports/tests/disagreements"

	@startdate, @enddate, @periodString = parsePeriod(params[:period].downcase)
	@selectedFlags, @appTypeString = parseFlags(params[:flags])

	@matches = Array.new
	Test.allWithFlags(@selectedFlags, :pending_at.not => nil, :complete => true, :closed_at => (@startdate..@enddate)).each do |t|
		if(t.pending_pass != t.pass)
			@matches << t
		end
	end

	erb :reports/disagreements"
end

- (Object) GET '/reports/tests/disagreementsOverTime/?'



348
349
350
# File 'routes/reports.rb', line 348

get '/reports/tests/disagreementsOverTime/?' do
	redirect "/reports/tests/disagreementsOverTime/default/month/all"
end

- (Object) GET '/reports/tests/disagreementsOverTime/:period/:interval/:flags/?'

Approval Flow Disagreements/Time #



253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
# File 'routes/reports.rb', line 253

get '/reports/tests/disagreementsOverTime/:period/:interval/:flags/?' do
	@formsub = "/reports/tests/disagreementsOverTime"
	@intervals = ["Day", "Week", "Month", "Quarter", "Year"]
	
	@int, @intString = parseInterval(params[:interval].downcase, @intervals)
	@startdate, @enddate, @periodString = parsePeriod(params[:period].downcase)
	@selectedFlags, @appTypeString = parseFlags(params[:flags])

	@labels = Array.new
	@counts = Array.new
	@matches = Array.new
	if(@int == "day")
		@startdate.upto(@enddate) do |date|
			count = 0
			@labels << date.strftime('%m-%d-%Y')
			Test.allWithFlags(@selectedFlags, :pending_at.not => nil, :complete => true, :closed_at => date).each do |t|
				if(t.pending_pass != t.pass)
					count += 1
					@matches << t
				end
			end
			@counts << count
		end
	elsif(@int == "week")
		@startdate.step(@enddate, 7) do |date|
			count = 0
			@labels << date.strftime('%m-%d-%Y')
			Test.allWithFlags(@selectedFlags, :pending_at.not => nil, :complete => true, :closed_at => (date..date+7)).each do |t|
				if(t.pending_pass != t.pass)
					count += 1
					@matches << t
				end
			end
			@counts << count
		end
	elsif(@int == "month")
		date = Date.new(@startdate.year, @startdate.month, 1)
		while date < @enddate do
			count = 0
			@labels << date.strftime('%B, %Y')
			Test.allWithFlags(@selectedFlags, :pending_at.not => nil, :complete => true, :closed_at => (date..date >> 1)).each do |t|
				if(t.pending_pass != t.pass)
					count += 1
					@matches << t
				end
			end
			@counts << count
			date = (date >> 1)
		end
	elsif(@int == "quarter")
		first = (startOfQuarter(@startdate) < @startdate) ? @startdate : startOfQuarter(@startdate)
		last = (endOfQuarter(@startdate) > @enddate) ? @enddate : endOfQuarter(@startdate)
		while first < @enddate do
			count = 0
			@labels << "Q" + qnum(first).to_s + ", FY " + fy(first).to_s
			Test.allWithFlags(@selectedFlags, :pending_at.not => nil, :complete => true, :closed_at => ((first.to_datetime)...(last.to_datetime.end_of_day))).each do |t|
				if(t.pending_pass != t.pass)
					count += 1
					@matches << t
				end
			end
			@counts << count
			first = startOfQuarter(first >> 3)
			last = (endOfQuarter(first) > @enddate) ? @enddate : endOfQuarter(first)
		end
	elsif(@int == "year")
		first = @startdate.to_date
		last = Date.new(first.year, 12, 31)
		last = @enddate if @enddate < last
		while first < @enddate do
			count = 0
			@labels << first.strftime('%Y')
			Test.allWithFlags(@selectedFlags, :pending_at.not => nil, :complete => true, :closed_at => ((first.to_datetime)...(last.to_datetime.end_of_day))).each do |t|
				if(t.pending_pass != t.pass)
					count += 1
					@matches << t
				end
			end
			@counts << count
			first = Date.new((first.year+1), 1, 1)
			last = Date.new(first.year, 12, 31)
			last = @enddate.to_date if @enddate < last
		end
	end

	erb :reports/disagreementsOverTime"
end

- (Object) GET '/reports/tests/resolutionsOverTime/?'



1776
1777
1778
# File 'routes/reports.rb', line 1776

get '/reports/tests/resolutionsOverTime/?' do
	redirect "/reports/tests/resolutionsOverTime/default/month/all/all"
end

- (Object) GET '/reports/tests/resolutionsOverTime/:period/:interval/:flags/:rt/?'

Resolutions over Time #



1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
# File 'routes/reports.rb', line 1597

get '/reports/tests/resolutionsOverTime/:period/:interval/:flags/:rt/?' do
	@formsub = "/reports/tests/resolutionsOverTime"
	@intervals = ["Day", "Week", "Month", "Quarter", "Year"]
	
	@int, @intString = parseInterval(params[:interval].downcase, @intervals)
	@startdate, @enddate, @periodString = parsePeriod(params[:period].downcase)
	@selectedFlags, @appTypeString = parseFlags(params[:flags])
	@selectedRecordTypes = parseRt(params[:rt])

	@labels = Array.new
	@appCounts = Array.new
	@testCounts = Array.new
	@passCounts = Array.new
	@failCounts = Array.new

	if(@int == "day")
		@startdate.upto(@enddate) do |date|
			@labels << date.strftime('%a %m-%d-%Y')
			act = 0
			passct = 0
			failct = 0
			
			appsIncluded = Array.new
			Test.allWithFlags(@selectedFlags, :complete => true, :closed_at => (date.to_datetime.beginning_of_day..(date.to_datetime.end_of_day)), Test.application.record_type => @selectedRecordTypes).each do |t|
				if(t.complete && t.pass)
					passct += 1
				else
					failct += 1
				end

				if(!appsIncluded.include?(t.application_id))
					act += 1
					appsIncluded << t.application_id
				end
			end

			@testCounts << (passct + failct)
			@passCounts << passct
			@failCounts << failct
			@appCounts << act
		end
	elsif(@int == "week")
		@startdate.step(@enddate, 7) do |date|
			@labels << date.strftime('%m-%d-%Y')
			act = 0
			passct = 0
			failct = 0
			
			appsIncluded = Array.new
			Test.allWithFlags(@selectedFlags, :complete => true, :closed_at => (date..(date+7)).to_datetime.end_of_day, Test.application.record_type => @selectedRecordTypes).each do |t|
				if(t.complete && t.pass)
					passct += 1
				else
					failct += 1
				end

				if(!appsIncluded.include?(t.application_id))
					act += 1
					appsIncluded << t.application_id
				end
			end

			@testCounts << (passct + failct)
			@passCounts << passct
			@failCounts << failct
			@appCounts << act
		end
	elsif(@int == "month")
		date = Date.new(@startdate.year, @startdate.month, 1)
		while date < @enddate do
			@labels << date.strftime('%B, %Y')
			act = 0
			passct = 0
			failct = 0
			
			appsIncluded = Array.new
			Test.allWithFlags(@selectedFlags, :complete => true, :closed_at => (date..(date.end_of_month).to_datetime.end_of_day), Test.application.record_type => @selectedRecordTypes).each do |t|
				if(t.complete && t.pass)
					passct += 1
				else
					failct += 1
				end

				if(!appsIncluded.include?(t.application_id))
					act += 1
					appsIncluded << t.application_id
				end
			end

			@testCounts << (passct + failct)
			@passCounts << passct
			@failCounts << failct
			@appCounts << act

			date = (date >> 1)
		end
	elsif(@int == "quarter")
		first = (startOfQuarter(@startdate) < @startdate) ? @startdate : startOfQuarter(@startdate)
		last = (endOfQuarter(@startdate) > @enddate) ? @enddate : endOfQuarter(@startdate)
		while first < @enddate do
			@labels << "Q" + qnum(first).to_s + ", FY " + fy(first).to_s
			act = 0
			passct = 0
			failct = 0
			
			appsIncluded = Array.new
			Test.allWithFlags(@selectedFlags, :complete => true, :closed_at => (date..(date.end_of_month).to_datetime.end_of_day), Test.application.record_type => @selectedRecordTypes).each do |t|
				if(t.complete && t.pass)
					passct += 1
				else
					failct += 1
				end

				if(!appsIncluded.include?(t.application_id))
					act += 1
					appsIncluded << t.application_id
				end
			end

			@testCounts << (passct + failct)
			@passCounts << passct
			@failCounts << failct
			@appCounts << act

			first = startOfQuarter(first >> 3)
			last = (endOfQuarter(first) > @enddate) ? @enddate : endOfQuarter(first)
		end
	elsif(@int == "year")
		first = @startdate.to_date
		last = Date.new(first.year, 12, 31)
		last = @enddate if @enddate < last
		while first < @enddate do
			@labels << first.strftime('%Y')
			act = 0
			passct = 0
			failct = 0
			
			appsIncluded = Array.new
			Test.allWithFlags(@selectedFlags, :complete => true, :closed_at => ((first.to_datetime)...(last.to_datetime.end_of_day)), Test.application.record_type => @selectedRecordTypes).each do |t|
				if(t.complete && t.pass)
					passct += 1
				else
					failct += 1
				end

				if(!appsIncluded.include?(t.application_id))
					act += 1
					appsIncluded << t.application_id
				end
			end

			@testCounts << (passct + failct)
			@passCounts << passct
			@failCounts << failct
			@appCounts << act

			first = Date.new((first.year+1), 1, 1)
			last = Date.new(first.year, 12, 31)
			last = @enddate.to_date if @enddate < last
		end
	end

	@totalTests = @testCounts.inject(0, :+)
	@totalPasses = @passCounts.inject(0, :+)
	@totalFails = @failCounts.inject(0, :+)
	@totalApps = @appCounts.inject(0, :+)

	erb :reports/resolutionsOverTime"
end

- (Object) GET '/reports/tests/searchByVuln/?'

Search Tests by Vuln Type #



1784
1785
1786
1787
1788
1789
1790
1791
# File 'routes/reports.rb', line 1784

get '/reports/tests/searchByVuln/?' do
	@formsub = "/reports/tests/searchByVuln"

	@vts = VulnType.all().sort{ |x,y| x.name <=> y.name}
	@selectedFlags, @appTypeString = parseFlags('all')

	erb :reports/testsByVuln"
end

- (Object) GET '/reports/tests/testsOverTime/?'



1589
1590
1591
# File 'routes/reports.rb', line 1589

get '/reports/tests/testsOverTime/?' do
	redirect "/reports/tests/testsOverTime/default/month/all/all"
end

- (Object) GET '/reports/tests/testsOverTime/:period/:interval/:flags/:rt/?'

Tests and Apps over Time #



1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
# File 'routes/reports.rb', line 1382

get '/reports/tests/testsOverTime/:period/:interval/:flags/:rt/?' do
	@formsub = "/reports/tests/testsOverTime"
	@intervals = ["Day", "Week", "Month", "Quarter", "Year"]
	
	@int, @intString = parseInterval(params[:interval].downcase, @intervals)
	@startdate, @enddate, @periodString = parsePeriod(params[:period].downcase)
	@selectedFlags, @appTypeString = parseFlags(params[:flags])
	@selectedRecordTypes = parseRt(params[:rt])

	@labels = Array.new
	@appCounts = Array.new
	@testCounts = Array.new
	@nonConTestCounts = Array.new
	@conTestCounts = Array.new

	appsIncludedTotal = Array.new
	@appCountTotal = 0

	if(@int == "day")
		@startdate.upto(@enddate) do |date|
			@labels << date.strftime('%a %m-%d-%Y')
			act = 0
			stct = 0
			ctct = 0
			
			appsIncluded = Array.new
			Test.allWithFlags(@selectedFlags, :complete => true, :closed_at => (date.to_datetime.beginning_of_day..(date.to_datetime.end_of_day)), Test.application.record_type => @selectedRecordTypes).each do |t|
				if(t.contractor_test)
					ctct += 1
				else
					stct += 1
				end

				if(!appsIncluded.include?(t.application_id))
					act += 1
					appsIncluded << t.application_id
				end

				if(!appsIncludedTotal.include?(t.application_id))
					@appCountTotal += 1
					appsIncludedTotal << t.application_id
				end
			end

			@testCounts << (stct + ctct)
			@nonConTestCounts << stct
			@conTestCounts << ctct
			@appCounts << act
		end
	elsif(@int == "week")
		@startdate.step(@enddate, 7) do |date|
			@labels << date.strftime('%m-%d-%Y')
			act = 0
			stct = 0
			ctct = 0
			
			appsIncluded = Array.new
			Test.allWithFlags(@selectedFlags, :complete => true, :closed_at => (date.to_datetime.beginning_of_day..(date+7).to_datetime.end_of_day), Test.application.record_type => @selectedRecordTypes).each do |t|
				if(t.contractor_test)
					ctct += 1
				else
					stct += 1
				end

				if(!appsIncluded.include?(t.application_id))
					act += 1
					appsIncluded << t.application_id
				end

				if(!appsIncludedTotal.include?(t.application_id))
					@appCountTotal += 1
					appsIncludedTotal << t.application_id
				end
			end

			@testCounts << (stct + ctct)
			@nonConTestCounts << stct
			@conTestCounts << ctct
			@appCounts << act
		end
	elsif(@int == "month")
		date = Date.new(@startdate.year, @startdate.month, 1)
		while date < @enddate do
			@labels << date.strftime('%B, %Y')
			act = 0
			stct = 0
			ctct = 0
			
			appsIncluded = Array.new
			Test.allWithFlags(@selectedFlags, :complete => true, :closed_at => (date.to_datetime.beginning_of_day..(date.end_of_month.to_datetime.end_of_day)), Test.application.record_type => @selectedRecordTypes).each do |t|
				if(t.contractor_test)
					ctct += 1
				else
					stct += 1
				end

				if(!appsIncluded.include?(t.application_id))
					act += 1
					appsIncluded << t.application_id
				end

				if(!appsIncludedTotal.include?(t.application_id))
					@appCountTotal += 1
					appsIncludedTotal << t.application_id
				end
			end

			@testCounts << (stct + ctct)
			@nonConTestCounts << stct
			@conTestCounts << ctct
			@appCounts << act

			date = (date >> 1)
		end
	elsif(@int == "quarter")
		first = (startOfQuarter(@startdate) < @startdate) ? @startdate : startOfQuarter(@startdate)
		last = (endOfQuarter(@startdate) > @enddate) ? @enddate : endOfQuarter(@startdate)
		while first < @enddate do
			@labels << "Q" + qnum(first).to_s + ", FY " + fy(first).to_s
			act = 0
			stct = 0
			ctct = 0
			
			appsIncluded = Array.new
			Test.allWithFlags(@selectedFlags, :complete => true, :closed_at => ((first.to_datetime.beginning_of_day)...(last.to_datetime.end_of_day)), Test.application.record_type => @selectedRecordTypes).each do |t|
				if(t.contractor_test)
					ctct += 1
				else
					stct += 1
				end

				if(!appsIncluded.include?(t.application_id))
					act += 1
					appsIncluded << t.application_id
				end

				if(!appsIncludedTotal.include?(t.application_id))
					@appCountTotal += 1
					appsIncludedTotal << t.application_id
				end
			end

			@testCounts << (stct + ctct)
			@nonConTestCounts << stct
			@conTestCounts << ctct
			@appCounts << act

			first = startOfQuarter(first >> 3)
			last = (endOfQuarter(first) > @enddate) ? @enddate : endOfQuarter(first)
		end
	elsif(@int == "year")
		first = @startdate.to_date
		last = Date.new(first.year, 12, 31)
		last = @enddate if @enddate < last
		while first < @enddate do
			@labels << first.strftime('%Y')
			act = 0
			stct = 0
			ctct = 0
			
			appsIncluded = Array.new
			Test.allWithFlags(@selectedFlags, :complete => true, :closed_at => ((first.to_datetime.beginning_of_day)...(last.to_datetime.end_of_day)), Test.application.record_type => @selectedRecordTypes).each do |t|
				if(t.contractor_test)
					ctct += 1
				else
					stct += 1
				end

				if(!appsIncluded.include?(t.application_id))
					act += 1
					appsIncluded << t.application_id
				end

				if(!appsIncludedTotal.include?(t.application_id))
					@appCountTotal += 1
					appsIncludedTotal << t.application_id
				end
			end

			@testCounts << (stct + ctct)
			@nonConTestCounts << stct
			@conTestCounts << ctct
			@appCounts << act

			first = Date.new((first.year+1), 1, 1)
			last = Date.new(first.year, 12, 31)
			last = @enddate.to_date if @enddate < last
		end
	end

	@totalTests = @testCounts.inject(0, :+)
	@totalNonConTests = @nonConTestCounts.inject(0, :+)
	@totalConTests = @conTestCounts.inject(0, :+)
	@totalApps = @appCounts.inject(0, :+)

	erb :reports/testsOverTime"
end

- (Object) GET '/reports/tests/testsToPass/?'



873
874
875
# File 'routes/reports.rb', line 873

get '/reports/tests/testsToPass/?' do
	redirect "/reports/tests/testsToPass/default/month/all/all"
end

- (Object) GET '/reports/tests/testsToPass/:period/:interval/:flags/:rt/?'

Tests to Pass #



641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
# File 'routes/reports.rb', line 641

get '/reports/tests/testsToPass/:period/:interval/:flags/:rt/?' do
	@formsub = "/reports/tests/testsToPass"
	@intervals = ["Month", "Quarter", "Year"]

	@int, @intString = parseInterval(params[:interval].downcase, @intervals)
	@selectedFlags, @appTypeString = parseFlags(params[:flags])
	@startdate, @enddate, @periodString = parsePeriod(params[:period].downcase)
	@selectedRecordTypes = parseRt(params[:rt])

	@labels = Array.new
	@counts = Array.new
	@maxes = Array.new
	@maxApps = Array.new
	@mins = Array.new
	@minApps = Array.new
	@apps = Array.new
	@tests = Array.new
	if(@int == "month")
		date = Date.new(@startdate.year, @startdate.month, 1)
		while date < @enddate do
			@labels << date.strftime('%B, %Y')

			total = 0
			totalApps = 0
			max = 0
			maxapp = nil
			min = 0
			minapp = nil

			tests = Test.allWithFlags(@selectedFlags, :fields => [:application_id], :unique => true, Test.application.record_type => @selectedRecordTypes, :complete => true, :pass => true, :closed_at => (date..(date.end_of_month).to_datetime.end_of_day), :order => [:application_id.asc])

			tests.each do |t|
				aid = t.application_id
				tests = Test.all(:application_id => aid)

				numPasses = 0
				ttp = 0

				tests.each do |t|
					if(t.pass)
						numPasses += 1
					end
				end

				if(numPasses == 1)
					ttp = tests.size
				else
					ttp = 1
					tests.reverse.drop(1).each do |t|
						if(!t.pass)
							ttp += 1
						else
							break
						end
					end
				end

				total += ttp
				totalApps += 1

				if(ttp > max)
					max = ttp
					maxapp = Application.get(aid)
				end

				if(ttp < min || min == 0)
					min = ttp
					minapp = Application.get(aid)
				end
			end
			
			@counts << ((totalApps == 0) ? 0 : (total.to_f/totalApps.to_f).round(3))
			@maxes << max
			@maxApps << maxapp
			@mins << min
			@minApps << minapp
			@apps << totalApps
			@tests << total
			
			date = (date >> 1)
		end
	elsif(@int == "quarter")
		first = (startOfQuarter(@startdate) < @startdate) ? @startdate : startOfQuarter(@startdate)
		last = (endOfQuarter(@startdate) > @enddate) ? @enddate : endOfQuarter(@startdate)
		while first < @enddate do
			@labels << "Q" + qnum(first).to_s + ", FY " + fy(first).to_s
			
			total = 0
			totalApps = 0
			max = 0
			maxapp = nil
			min = 0
			minapp = nil
			
			tests = Test.allWithFlags(@selectedFlags, :fields => [:application_id], :unique => true, Test.application.record_type => @selectedRecordTypes, :complete => true, :pass => true, :closed_at => (first.to_datetime..(last.to_datetime.end_of_day)), :order => [:application_id.asc])

			tests.each do |t|
				aid = t.application_id
				tests = Test.all(:application_id => aid)

				numPasses = 0
				ttp = 0

				tests.each do |t|
					if(t.pass)
						numPasses += 1
					end
				end

				if(numPasses == 1)
					ttp = tests.size
				else
					ttp = 1
					tests.reverse.drop(1).each do |t|
						if(!t.pass)
							ttp += 1
						else
							break
						end
					end
				end

				total += ttp
				totalApps += 1

				if(ttp > max)
					max = ttp
					maxapp = Application.get(aid)
				end

				if(ttp < min || min == 0)
					min = ttp
					minapp = Application.get(aid)
				end
			end

			@counts << ((totalApps == 0) ? 0 : (total.to_f/totalApps.to_f).round(3))
			@maxes << max
			@maxApps << maxapp
			@mins << min
			@minApps << minapp
			@apps << totalApps
			@tests << total

			first = startOfQuarter(first >> 3)
			last = (endOfQuarter(first) > @enddate) ? @enddate : endOfQuarter(first)
		end
	elsif(@int == "year")
		first = @startdate.to_date
		last = Date.new(first.year, 12, 31)
		last = @enddate if @enddate < last
		while first < @enddate do
			@labels << first.strftime('%Y')
			
			total = 0
			totalApps = 0
			max = 0
			maxapp = nil
			min = 0
			minapp = nil
			
			tests = Test.allWithFlags(@selectedFlags, :fields => [:application_id], :unique => true, Test.application.record_type => @selectedRecordTypes, :complete => true, :pass => true, :closed_at => (first.to_datetime..(last.to_datetime.end_of_day)), :order => [:application_id.asc])

			tests.each do |t|
				aid = t.application_id
				tests = Test.all(:application_id => aid)

				numPasses = 0
				ttp = 0

				tests.each do |t|
					if(t.pass)
						numPasses += 1
					end
				end

				if(numPasses == 1)
					ttp = tests.size
				else
					ttp = 1
					tests.reverse.drop(1).each do |t|
						if(!t.pass)
							ttp += 1
						else
							break
						end
					end
				end

				total += ttp
				totalApps += 1

				if(ttp > max)
					max = ttp
					maxapp = Application.get(aid)
				end

				if(ttp < min || min == 0)
					min = ttp
					minapp = Application.get(aid)
				end
			end

			@counts << ((totalApps == 0) ? 0 : (total.to_f/totalApps.to_f).round(3))
			@maxes << max
			@maxApps << maxapp
			@mins << min
			@minApps << minapp
			@apps << totalApps
			@tests << total

			first = Date.new((first.year+1), 1, 1)
			last = Date.new(first.year, 12, 31)
			last = @enddate.to_date if @enddate < last
		end
	end

	@totalApps = @apps.inject(0, :+)
	@totalTests = @tests.inject(0, :+)

	erb :reports/testsToPass"
end

- (Object) GET '/reports/tests/testTimes/?'



474
475
476
# File 'routes/reports.rb', line 474

get '/reports/tests/testTimes/?' do
	redirect "/reports/tests/testTimes/default/month/all/all"
end

- (Object) GET '/reports/tests/testTimes/:period/:interval/:flags/:rt/?'

Test Times to Completion #



356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
# File 'routes/reports.rb', line 356

get '/reports/tests/testTimes/:period/:interval/:flags/:rt/?' do
	@formsub = "/reports/tests/testTimes"
	@intervals = ["Month", "Quarter", "Year"]
	
	@int, @intString = parseInterval(params[:interval].downcase, @intervals)
	@selectedFlags, @appTypeString = parseFlags(params[:flags])
	@startdate, @enddate, @periodString = parsePeriod(params[:period].downcase)
	@selectedRecordTypes = parseRt(params[:rt])

	@labels = Array.new
	@counts = Array.new
	@conCounts = Array.new
	@approvalCounts = Array.new
	@matches = Array.new
	if(@int == "month")
		date = Date.new(@startdate.year, @startdate.month, 1)
		while date < @enddate do
			@labels << date.strftime('%B, %Y')

			totalDays = 0
			conTotalDays = 0
			totalTests = 0
			conTotalTests = 0
			totalDaysToApprove = 0
			Test.allWithFlags(@selectedFlags, :complete => true, :closed_at => (date..(date.end_of_month).to_datetime.end_of_day), Test.application.record_type => @selectedRecordTypes).each do |t|
				t.con_closed_at = t.closed_at if t.con_closed_at.nil?

				if(t.contractor_test)
					conTotalDays += t.closed_at - t.created_at
					totalDaysToApprove += t.closed_at - t.con_closed_at
					conTotalTests += 1
				else
					totalDays += t.closed_at - t.created_at
					totalTests += 1					
				end
			end
			@counts << ((totalTests == 0) ? 0.0 : (totalDays.to_f/totalTests.to_f).round(2))
			@conCounts << ((conTotalTests == 0) ? 0.0 : (conTotalDays.to_f/conTotalTests.to_f).round(2))
			@approvalCounts << ((conTotalTests == 0) ? 0.0 : (totalDaysToApprove.to_f/conTotalTests.to_f).round(2))

			date = (date >> 1)
		end
	elsif(@int == "quarter")
		first = (startOfQuarter(@startdate) < @startdate) ? @startdate : startOfQuarter(@startdate)
		last = (endOfQuarter(@startdate) > @enddate) ? @enddate : endOfQuarter(@startdate)
		while first < @enddate do
			@labels << "Q" + qnum(first).to_s + ", FY " + fy(first).to_s
			
			totalDays = 0
			conTotalDays = 0
			totalTests = 0
			conTotalTests = 0
			totalDaysToApprove = 0
			Test.allWithFlags(@selectedFlags, :complete => true, :closed_at => ((first.to_datetime)...(last.to_datetime.end_of_day)), Test.application.record_type => @selectedRecordTypes).each do |t|
				t.con_closed_at = t.closed_at if t.con_closed_at.nil?

				if(t.contractor_test)
					conTotalDays += t.closed_at - t.created_at
					totalDaysToApprove += t.closed_at - t.con_closed_at
					conTotalTests += 1
				else
					totalDays += t.closed_at - t.created_at
					totalTests += 1					
				end
			end
			@counts << ((totalTests == 0) ? 0.0 : (totalDays.to_f/totalTests.to_f).round(2))
			@conCounts << ((conTotalTests == 0) ? 0.0 : (conTotalDays.to_f/conTotalTests.to_f).round(2))
			@approvalCounts << ((conTotalTests == 0) ? 0.0 : (totalDaysToApprove.to_f/conTotalTests.to_f).round(2))

			first = startOfQuarter(first >> 3)
			last = (endOfQuarter(first) > @enddate) ? @enddate : endOfQuarter(first)
		end
	elsif(@int == "year")
		first = @startdate.to_date
		last = Date.new(first.year, 12, 31)
		last = @enddate if @enddate < last
		while first < @enddate do
			@labels << first.strftime('%Y')
			
			totalDays = 0
			conTotalDays = 0
			totalTests = 0
			conTotalTests = 0
			totalDaysToApprove = 0
			Test.allWithFlags(@selectedFlags, :complete => true, :closed_at => ((first.to_datetime)...(last.to_datetime.end_of_day)), Test.application.record_type => @selectedRecordTypes).each do |t|
				t.con_closed_at = t.closed_at if t.con_closed_at.nil?

				if(t.contractor_test)
					conTotalDays += t.closed_at - t.created_at
					totalDaysToApprove += t.closed_at - t.con_closed_at
					conTotalTests += 1
				else
					totalDays += t.closed_at - t.created_at
					totalTests += 1					
				end
			end
			@counts << ((totalTests == 0) ? 0.0 : (totalDays.to_f/totalTests.to_f).round(2))
			@conCounts << ((conTotalTests == 0) ? 0.0 : (conTotalDays.to_f/conTotalTests.to_f).round(2))
			@approvalCounts << ((conTotalTests == 0) ? 0.0 : (totalDaysToApprove.to_f/conTotalTests.to_f).round(2))

			first = Date.new((first.year+1), 1, 1)
			last = Date.new(first.year, 12, 31)
			last = @enddate.to_date if @enddate < last
		end
	end

	erb :reports/testTimes"
end

- (Object) GET '/reports/tests/ttr/?'



633
634
635
# File 'routes/reports.rb', line 633

get '/reports/tests/ttr/?' do
	redirect "/reports/tests/ttr/default/month/all/all"
end

- (Object) GET '/reports/tests/ttr/:period/:interval/:flags/:rt/?'

Total Time to Test Resolution #



482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
# File 'routes/reports.rb', line 482

get '/reports/tests/ttr/:period/:interval/:flags/:rt/?' do
	@formsub = "/reports/tests/ttr"
	@intervals = ["Month", "Quarter", "Year"]

	@int, @intString = parseInterval(params[:interval].downcase, @intervals)
	@selectedFlags, @appTypeString = parseFlags(params[:flags])
	@startdate, @enddate, @periodString = parsePeriod(params[:period].downcase)
	@selectedRecordTypes = parseRt(params[:rt])

	@labels = Array.new
	@counts = Array.new
	@maxes = Array.new
	@maxTests = Array.new
	@mins = Array.new
	@minTests = Array.new
	@numTests = Array.new
	if(@int == "month")
		date = Date.new(@startdate.year, @startdate.month, 1)
		while date < @enddate do
			@labels << date.strftime('%B, %Y')

			totalWks = 0.0
			totalTests = 0
			max = 0.0
			maxtest = nil
			min = 0.0
			mintest = nil
			Test.allWithFlags(@selectedFlags, :complete => true, :closed_at => (date..(date >> 1).to_datetime.end_of_day), Test.application.record_type => @selectedRecordTypes).each do |t|
				if(t.wksAtClose > max)
					max = t.wksAtClose
					maxtest = t
				end

				if(t.wksAtClose < min || min == 0.0)
					min = t.wksAtClose
					mintest = t
				end

				totalWks += t.wksAtClose
				totalTests += 1
			end
			@counts << ((totalTests == 0) ? 0.0 : (totalWks/totalTests.to_f))
			@maxes << max
			@maxTests << maxtest
			@mins << min
			@minTests << mintest
			@numTests << totalTests
			
			date = (date >> 1)
		end
	elsif(@int == "quarter")
		first = (startOfQuarter(@startdate) < @startdate) ? @startdate : startOfQuarter(@startdate)
		last = (endOfQuarter(@startdate) > @enddate) ? @enddate : endOfQuarter(@startdate)
		while first < @enddate do
			@labels << "Q" + qnum(first).to_s + ", FY " + fy(first).to_s
			
			totalWks = 0.0
			totalTests = 0
			max = 0.0
			maxtest = nil
			min = 0.0
			mintest = nil
			Test.allWithFlags(@selectedFlags, :complete => true, :closed_at => ((first.to_datetime)...(last.to_datetime.end_of_day)), Test.application.record_type => @selectedRecordTypes).each do |t|
				if(t.wksAtClose > max)
					max = t.wksAtClose
					maxtest = t
				end

				if(t.wksAtClose < min || min == 0.0)
					min = t.wksAtClose
					mintest = t
				end

				totalWks += t.wksAtClose
				totalTests += 1
			end
			@counts << ((totalTests == 0) ? 0.0 : (totalWks/totalTests.to_f))
			@maxes << max
			@maxTests << maxtest
			@mins << min
			@minTests << mintest
			@numTests << totalTests

			first = startOfQuarter(first >> 3)
			last = (endOfQuarter(first) > @enddate) ? @enddate : endOfQuarter(first)
		end
	elsif(@int == "year")
		first = @startdate.to_date
		last = Date.new(first.year, 12, 31)
		last = @enddate if @enddate < last
		while first < @enddate do
			@labels << first.strftime('%Y')
			
			totalWks = 0.0
			totalTests = 0
			max = 0.0
			maxtest = nil
			min = 0.0
			mintest = nil
			Test.allWithFlags(@selectedFlags, :complete => true, :closed_at => ((first.to_datetime)...(last.to_datetime.end_of_day)), Test.application.record_type => @selectedRecordTypes).each do |t|
				if(t.wksAtClose > max)
					max = t.wksAtClose
					maxtest = t
				end

				if(t.wksAtClose < min || min == 0.0)
					min = t.wksAtClose
					mintest = t
				end

				totalWks += t.wksAtClose
				totalTests += 1
			end
			@counts << ((totalTests == 0) ? 0.0 : (totalWks/totalTests.to_f))
			@maxes << max
			@maxTests << maxtest
			@mins << min
			@minTests << mintest
			@numTests << totalTests

			first = Date.new((first.year+1), 1, 1)
			last = Date.new(first.year, 12, 31)
			last = @enddate.to_date if @enddate < last
		end
	end

	@totalTests = @numTests.inject(0, :+)
	@avgTTR = 0
	num = 0
	denom = 0
	@counts.each_with_index do |c, i|
		num += c*@numTests[i]
		denom += @numTests[i]
	end

	if(denom > 0)
		@avgTTR = (num/denom)
	end

	erb :reports/timeToResolution"
end

- (Object) GET '/reports/vulns/vulnerabilitiesOverTime/?'



1075
1076
1077
# File 'routes/reports.rb', line 1075

get '/reports/vulns/vulnerabilitiesOverTime/?' do
	redirect "/reports/vulns/vulnerabilitiesOverTime/default/month/all/all"
end

- (Object) GET '/reports/vulns/vulnerabilitiesOverTime/:period/:interval/:flags/:rt/?'

Vulnerabilities Over Time #



927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
# File 'routes/reports.rb', line 927

get '/reports/vulns/vulnerabilitiesOverTime/:period/:interval/:flags/:rt/?' do
	@formsub = "/reports/vulns/vulnerabilitiesOverTime"
	@intervals = ["Day", "Week", "Month", "Quarter", "Year"]

	@int, @intString = parseInterval(params[:interval].downcase, @intervals)
	@startdate, @enddate, @periodString = parsePeriod(params[:period].downcase)
	@selectedFlags, @appTypeString = parseFlags(params[:flags])
	@selectedRecordTypes = parseRt(params[:rt])
	
	@datasets = Hash.new
	@datasets["All"] = Array.new
	@datasets["Custom/Other"] = Array.new
	VulnType.all().each do |vt|
		@datasets[vt.name] = Array.new
	end
	@labels = Array.new

	if(@int == "day")
		@startdate.upto(@enddate) do |date|
			@labels << date.strftime('%m-%d-%Y')
			allcount = 0
			
			@datasets.keys.each do |key|
				next if(key.downcase == "all" || key.downcase == "custom/other")
				vt = VulnType.getTypeByName(key)
				ct = Vulnerability.countWithFlags(@selectedFlags, :vulntype => vt.id, :verified => true, :falsepos => false, Vulnerability.test.application.record_type => @selectedRecordTypes, :created_at => (date...(date+1)))
				@datasets[key] << ct
				allcount += ct
			end
			
			otherCt = Vulnerability.countWithFlags(@selectedFlags, :vulntype => 0, :verified => true, :falsepos => false, Vulnerability.test.application.record_type => @selectedRecordTypes, :created_at => (date...(date+1)))
			
			@datasets["Custom/Other"] << otherCt
			allcount += otherCt

			@datasets["All"] << allcount
		end
	elsif(@int == "week")
		@startdate.step(@enddate, 7) do |date|
			@labels << date.strftime('%m-%d-%Y')
			allcount = 0
			
			@datasets.keys.each do |key|
				next if(key.downcase == "all" || key.downcase == "custom/other")
				vt = VulnType.getTypeByName(key)
				ct = Vulnerability.countWithFlags(@selectedFlags, :vulntype => vt.id, :verified => true, :falsepos => false, Vulnerability.test.application.record_type => @selectedRecordTypes, :created_at => (date...(date+7)))
				@datasets[key] << ct
				allcount += ct
			end

			otherCt = Vulnerability.countWithFlags(@selectedFlags, :vulntype => 0, :verified => true, :falsepos => false, Vulnerability.test.application.record_type => @selectedRecordTypes, :created_at => (date...(date+7)))
			
			@datasets["Custom/Other"] << otherCt
			allcount += otherCt

			@datasets["All"] << allcount
		end
	elsif(@int == "month")
		date = Date.new(@startdate.year, @startdate.month, 1)
		while date < @enddate do
			@labels << date.strftime('%B, %Y')
			allcount = 0

			@datasets.keys.each do |key|
				next if(key.downcase == "all" || key.downcase == "custom/other")
				vt = VulnType.getTypeByName(key)
				ct = Vulnerability.countWithFlags(@selectedFlags, :vulntype => vt.id, :verified => true, :falsepos => false, Vulnerability.test.application.record_type => @selectedRecordTypes, :created_at => (date..(date.end_of_month).to_datetime.end_of_day))
				@datasets[key] << ct
				allcount += ct
			end

			otherCt = Vulnerability.countWithFlags(@selectedFlags, :vulntype => 0, :verified => true, :falsepos => false, Vulnerability.test.application.record_type => @selectedRecordTypes, :created_at => (date..(date.end_of_month).to_datetime.end_of_day))
			
			@datasets["Custom/Other"] << otherCt
			allcount += otherCt

			@datasets["All"] << allcount

			date = (date >> 1)
		end
	elsif(@int == "quarter")
		first = (startOfQuarter(@startdate) < @startdate) ? @startdate : startOfQuarter(@startdate)
		last = (endOfQuarter(@startdate) > @enddate) ? @enddate : endOfQuarter(@startdate)
		while first < @enddate do
			@labels << "Q" + qnum(first).to_s + ", FY " + fy(first).to_s
			allcount = 0

			@datasets.keys.each do |key|
				next if(key.downcase == "all" || key.downcase == "custom/other")
				vt = VulnType.getTypeByName(key)
				ct = Vulnerability.countWithFlags(@selectedFlags, :vulntype => vt.id, :verified => true, :falsepos => false, Vulnerability.test.application.record_type => @selectedRecordTypes, :created_at => ((first.to_datetime)...(last.to_datetime.end_of_day)))
				@datasets[key] << ct
				allcount += ct
			end

			otherCt = Vulnerability.countWithFlags(@selectedFlags, :vulntype => 0, :verified => true, :falsepos => false, Vulnerability.test.application.record_type => @selectedRecordTypes, :created_at => ((first.to_datetime)...(last.to_datetime.end_of_day)))
			
			@datasets["Custom/Other"] << otherCt
			allcount += otherCt

			@datasets["All"] << allcount

			first = startOfQuarter(first >> 3)
			last = (endOfQuarter(first) > @enddate) ? @enddate : endOfQuarter(first)
		end
	elsif(@int == "year")
		first = @startdate.to_date
		last = Date.new(first.year, 12, 31)
		last = @enddate if @enddate < last
		while first < @enddate do
			@labels << first.strftime('%Y')
			allcount = 0
			
			@datasets.keys.each do |key|
				next if(key.downcase == "all" || key.downcase == "custom/other")
				vt = VulnType.getTypeByName(key)
				ct = Vulnerability.countWithFlags(@selectedFlags, :vulntype => vt.id, :verified => true, :falsepos => false, Vulnerability.test.application.record_type => @selectedRecordTypes, :created_at => ((first.to_datetime)...(last.to_datetime.end_of_day)))
				@datasets[key] << ct
				allcount += ct
			end

			otherCt = Vulnerability.countWithFlags(@selectedFlags, :vulntype => 0, :verified => true, :falsepos => false, Vulnerability.test.application.record_type => @selectedRecordTypes, :created_at => ((first.to_datetime)...(last.to_datetime.end_of_day)))

			@datasets["Custom/Other"] << otherCt
			allcount += otherCt

			@datasets["All"] << allcount

			first = Date.new((first.year+1), 1, 1)
			last = Date.new(first.year, 12, 31)
			last = @enddate.to_date if @enddate < last
		end
	end

	@totalVulns = @datasets["All"].inject(0, :+)

	erb :reports/vulnsOverTime"
end

- (Object) GET '/reports/vulns/VulnsByType/?'



919
920
921
# File 'routes/reports.rb', line 919

get '/reports/vulns/VulnsByType/?' do
	redirect "/reports/vulns/VulnsByType/default/all/all"
end

- (Object) GET '/reports/vulns/VulnsByType/:period/:flags/:rt/?'

Vulns By Type #



881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
# File 'routes/reports.rb', line 881

get '/reports/vulns/VulnsByType/:period/:flags/:rt/?' do
	@formsub = "/reports/vulns/VulnsByType"

	@startdate, @enddate, @periodString = parsePeriod(params[:period].downcase)
	@selectedFlags, @appTypeString = parseFlags(params[:flags])
	@selectedRecordTypes = parseRt(params[:rt])

	@labels = Array.new
	@counts = Array.new
	Vulnerability.allWithFlags(@selectedFlags, :created_at => (@startdate..@enddate), :verified => true, :falsepos => false, Vulnerability.test.application.record_type => @selectedRecordTypes).each do |v|
		if(v.vulntype == 0)
			thisLabel = "Custom / Other"
		else
			thisLabel = v.type_str
		end

		idx = @labels.index(thisLabel)
		if(idx.nil?)
			@labels << thisLabel
			@counts << 1
		else
			@counts[idx] += 1
		end
	end

	@totalVulns = @counts.inject(0, :+)

	erb :reports/vulnsbytype"
end

- (Object) GET '/reviews/:aid/?'



277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
# File 'routes/application.rb', line 277

get '/reviews/:aid/?' do
	cache = true
	if(params['cacheref'] == '1')
		cache = false
	end
	
	@app = Application.get(params[:aid])
	if(@app.nil?)
		@errstr = "Application not found"
		return erb :error 
	end

	halt 401, (erb :unauth) if(!canViewReview?(@app.id))

	#By the time we get here, this only evals true for Admins or maybe Supers
	if(@app.isPrivate && !userAllowedForApp(@session[:uid], @app.id) && !userWarnedForApp?(@session[:uid], @app.id))
		if(params[:warned] == "true")
			markUserWarnedApp(@session[:uid], @app.id)
			redirect "/reviews/#{@app.id}"
		else
			@tid = nil
			@aid = @app.id
			return erb :app_private_warning
		end
	end

	@pageTitle = @app.name
	@tests = @app.tests

	@comments = Comment.commentsForApp(@app.id, @session[:uid], @session[:org])
	@unreadComments = 0
	@comments.each do |c|
		@unreadComments += 1 if(c.isUnseen?(session[:uid]))
	end

	if(!params[:fromNotif].nil?)
		@fromNotif = true
	end

	if(RecordType.get(@app.record_type).isLinked)
		if(@app.isLinked?)
			begin
				vrloPanel = @app.linkedObjectInfoPanel(@session[:uid], params, env)
			rescue Exception => e
				Rollbar.error(e, "Unable to generate VRLO Info Panel", {:vrlo_key => @app.getVRLO.vrlo_key, :aid => @app.id, :vrlo_eid => @app.linkId})
				vrloPanel = {:success => false, :errstr => "Exception while getting Linked Object data. Exception logged."}
			end

			if(!vrloPanel[:success])
				@vrloError = true
				@vrloErrorStr = vrloPanel[:errstr]
				@VRLOInfoPanelHTML = nil
				@VRLOAlerts = nil
				@VRLOMenuItems = nil
			else
				@VRLOInfoPanelHTML = vrloPanel[:infoPanelHtml]
				@VRLOAlerts = vrloPanel[:alerts]
				
				@VRLOMenuItems = Array.new
				menuItems = vrloPanel[:customMenuItems]
				#check auth for each
				menuItems.each do |m|
					authOk = true
					if(!m[:authMethods].nil? && m[:authMethods].size > 0)
						m[:authMethods].each do |am|
							amMethod = am[0]
							amArgs = am[1]
							begin
								if(!amArgs.nil? && amArgs.size > 0)
									amResult = send(amMethod, amArgs)
								else
									amResult = send(amMethod)
								end
							rescue
								authOk = false
							end

							if(!amResult)
								authOk = false
							end
						end
					end

					if(authOk)
						@VRLOMenuItems << m
					end
				end
			end
		else
			@unlinkedApp = true
			@VRLOInfoPanelHTML = nil
			@VRLOAlerts = nil
			@VRLOMenuItems = nil
		end
	else
		@unlinkedApp = false
		@VRLOInfoPanelHTML = nil
		@VRLOAlerts = nil
		@VRLOMenuItems = nil
	end
	
	erb :app_single
end

- (Object) GET '/reviews/:aid/audit/?'



381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
# File 'routes/application.rb', line 381

get '/reviews/:aid/audit/?' do
	@app = Application.get(params[:aid])
	if(@app.nil?)
		@errstr = "Application not found"
		return erb :error 
	end

	halt 401, (erb :unauth) if(!canViewReview?(@app.id))

	#By the time we get here, this only evals true for Admins or maybe Supers
	if(@app.isPrivate && !userAllowedForApp(@session[:uid], @app.id) && !userWarnedForApp?(@session[:uid], @app.id))
		if(params[:warned] == "true")
			markUserWarnedApp(@session[:uid], @app.id)
			redirect "/reviews/#{@app.id}/audit"
		else
			@tid = nil
			@aid = @app.id
			return erb :app_private_warning
		end
	end

	@pageTitle = @app.name

	@comments = Comment.commentsForApp(@app.id, @session[:uid], @session[:org])
	@unreadComments = 0
	@comments.each do |c|
		@unreadComments += 1 if(c.isUnseen?(session[:uid]))
	end

	#Get audit items together and sort
	@audits = AuditRecord.getAppAudits(@app.id)

	erb :app_audit
end

- (Object) GET '/reviews/:aid/delete/?'



727
728
729
730
731
732
733
734
735
736
737
738
# File 'routes/application.rb', line 727

get '/reviews/:aid/delete/?' do
	@app = Application.get(params[:aid])
	if(@app.nil?)
		@errstr = "Application not found"
		return erb :error 
	end

	halt 401, (erb :unauth) if(!canViewReview?(@app.id))
	halt 401, (erb :unauth) if(!canDeleteReview?(@app.id))

	erb :app_confirm_delete
end

- (Object) GET '/reviews/:aid/edit/?'



453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
# File 'routes/application.rb', line 453

get '/reviews/:aid/edit/?' do
	@app = Application.get(params[:aid])
	if(@app.nil?)
		@errstr = "Application not found"
		return erb :error 
	end

	halt 401, (erb :unauth) if(!canViewReview?(@app.id))

	@pageTitle = @app.name
	@isGlobal = ""
	if(@app.global)
		@isGlobal = "checked"
	end

	@isPrivate = ""
	if(@app.isPrivate)
		@isPrivate = "checked"
	end

	@appRecordTypes = getAllowedRTObjsForUser(@session[:uid])

	@orgs = Organization.all()
	@users = User.activeSorted()
	@canPassToContractor = (@app.canPassToContractor? && canPassToContractor?(@app.id))
	@availableFlags = Flag.all(:active => true)

	erb :app_edit
end

- (Object) GET '/reviews/:aid/permCheck/?'



430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
# File 'routes/application.rb', line 430

get '/reviews/:aid/permCheck/?' do
	only_admins!

	@app = Application.get(params[:aid])
	if(@app.nil?)
		@errstr = "Application not found"
		return erb :error 
	end

	@orgs = Array.new
	@users = Array.new

	Organization.all().each do |o|
		@orgs << {:org => o, :access => orgAllowedRT?(o.id, @app.record_type)}
	end

	User.all(:active => true, :order => [:org.asc]).each do |u|
		@users << {:user => u, :org => Organization.get(u.org), :access => canViewReview?(@app.id, u.id)}
	end

	erb :app_perm_list
end

- (Object) GET '/reviews/:aid/raw/?'



416
417
418
419
420
421
422
423
424
425
426
427
428
# File 'routes/application.rb', line 416

get '/reviews/:aid/raw/?' do
	only_admins!

	@app = Application.get(params[:aid])
	if(@app.nil?)
		@errstr = "Application not found"
		return erb :error 
	end

	halt 401, (erb :unauth) if(!canViewReview?(@app.id))

	erb :app_raw
end


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'routes/application.rb', line 10

get '/reviews/:aid/relink/?' do
	@app = Application.get(params[:aid])
	if(@app.nil?)
		@errstr = "Application not found"
		return erb :error 
	end

	if(!@app.recordType.isLinked)
		@errstr = "Record Type does not use a Linked Object"
		return erb :error
	end

	halt 401, (erb :unauth) if(!canViewReview?(@app.id))

	erb :app_relink
end


668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
# File 'routes/application.rb', line 668

get '/reviews/:aid/unlink/?' do
	@app = Application.get(params[:aid])
	if(@app.nil?)
		@errstr = "Application not found"
		return erb :error 
	end

	halt 401, (erb :unauth) if(!canViewReview?(@app.id))

	if(!@app.recordType.isLinked)
		@errstr = "Record Type does not use a Linked Object"
		return erb :error
	end

	if(!@app.isLinked?)
		@errstr = "This application is not linked"
		return erb :error
	end		

	erb :app_confirm_unlink
end

- (Object) GET '/reviews/active/?'



181
182
183
# File 'routes/application.rb', line 181

get '/reviews/active/?' do
	redirect "/reviews/active/default/all/all"
end

- (Object) GET '/reviews/active/:period/:flags/:rt?'



193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# File 'routes/application.rb', line 193

get '/reviews/active/:period/:flags/:rt?' do
	@formsub = "/reviews/active/"
	@intervals = []

	@selectedFlags, @appTypeString = parseFlags(params[:flags])
	@startdate, @enddate, @periodString = parsePeriod(params[:period], Date.today.beginning_of_year)
	@selectedRecordTypes = parseRt(params[:rt])

	@activeReviews = Array.new
	addedReviews = Array.new

	Test.allWithFlags(@selectedFlags, :complete => false, :order => [ :id.asc ], :created_at => (@startdate..@enddate), Test.application.record_type => @selectedRecordTypes).each do |t|
		next if(addedReviews.include?(t.application_id))
		next if(!canViewReview?(t.application_id))

		@activeReviews << {:app => Application.get(t.application_id), :test => t}
		addedReviews << t.application_id
	end

	@user = User.get(session[:uid])

	erb :app_active_list
end

- (Object) GET '/reviews/all/?'



217
218
219
# File 'routes/application.rb', line 217

get '/reviews/all/?' do
	redirect "/reviews/all/all/all/all/?os=0"
end

- (Object) GET '/reviews/all/:period/:flags/:rt/?'



229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
# File 'routes/application.rb', line 229

get '/reviews/all/:period/:flags/:rt/?' do
	@formsub = "/reviews/all/"
	@intervals = []

	period = params[:period].downcase
	@selectedFlags, @appTypeString = parseFlags(params[:flags])
	@startdate, @enddate, @periodString = parsePeriod(period)
	@selectedRecordTypes = parseRt(params[:rt])

	#Offset parse
	lim = 50

	if(params[:os].nil?)
		offset = 0
	else
		offset = params[:os].to_i
	end
	@total = Application.countWithFlags(@selectedFlags, :record_type => @selectedRecordTypes, :created_at => (@startdate..@enddate))

	@start = offset+1
	@end = (offset+lim > @total) ? @total : (offset+lim)

	@next = nil
	if(offset+lim < @total)
		@next = offset+lim
	end

	@last = nil
	if(offset > 0)
		@last = offset-lim
		if(@last < 0)
			@last = 0
		end
	end

	@reviews = Array.new

	Application.allWithFlags(@selectedFlags, :record_type => @selectedRecordTypes, :created_at => (@startdate..@enddate), :limit => lim, :offset => offset, :order => [ :id.desc ]).each do |a|
		if(a.isPrivate)
			next if !canViewReview?(a.id)
		end

		@reviews << a
	end

	erb :app_all_list
end

- (Object) GET '/reviews/my/?'



136
137
138
# File 'routes/application.rb', line 136

get '/reviews/my/?' do
	redirect "/reviews/my/all/all/all"
end

- (Object) GET '/reviews/my/:period/:flags/:rt/?'



148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'routes/application.rb', line 148

get '/reviews/my/:period/:flags/:rt/?' do
	@formsub = "/reviews/my/"
	@intervals = []

	@selectedFlags, @appTypeString = parseFlags(params[:flags])
	@startdate, @enddate, @periodString = parsePeriod(params[:period])
	@selectedRecordTypes = parseRt(params[:rt])

	@myActiveReviews = Array.new
	@myPastReviews = Array.new
	addedReviews = Array.new

	@user = User.get(session[:uid])

	Test.allWithFlags(@selectedFlags, :complete => false, :reviewer => @user.id, :order => [ :id.asc ], :created_at => (@startdate..@enddate), Test.application.record_type => @selectedRecordTypes).each do |t|
		next if(addedReviews.include?(t.application_id))
		next if(!canViewReview?(t.application_id))

		@myActiveReviews << {:app => Application.get(t.application_id), :test => t}
		addedReviews << t.application_id
	end

	Test.allWithFlags(@selectedFlags, :complete => true, :reviewer => @user.id, :order => [ :id.desc ], :created_at => (@startdate..@enddate), Test.application.record_type => @selectedRecordTypes).each do |t|
		next if(addedReviews.include?(t.application_id))
		next if(!canViewReview?(t.application_id))

		@myPastReviews << {:app => Application.get(t.application_id), :test => t}
		addedReviews << t.application_id
	end

	erb :app_list_my
end

- (Object) GET '/reviews/new/?'



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'routes/application.rb', line 66

get '/reviews/new/?' do
	halt 401, (erb :unauth) if reports_only?

	rts = getAllowedRTObjsForUser(@session[:uid])
	@appRecordTypes = Array.new
	rts.each do |rt|
		if(rt.active)
			@appRecordTypes << rt
		end
	end
	@defaultGeo = User.get(@session[:uid]).defaultGeo
	@users = User.activeSorted()

	erb :app_create
end

- (Object) GET '/search/?'



1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
# File 'web.rb', line 1193

get '/search/?' do
	if(params[:searchInput].nil? || params[:searchInput].empty?)
		return erb :search
	end

	@q = params[:searchInput]

	@allowedRecordTypesFull = getAllowedRTObjsForUser(@session[:uid])
	@allowedRecordTypes = @allowedRecordTypesFull.map{|rt| rt.id}
	
	if(params[:rt].nil? || params[:rt].to_s.downcase == "all")
		@selectedRecordTypes = @allowedRecordTypes
	else
		@selectedRecordTypes = @allowedRecordTypes & (params[:rt].map{|n| n.to_i})
		@selectedRecordTypes = @allowedRecordTypes if(@selectedRecordTypes.size == 0)
	end

	@reviewResults = Array.new
	@testResults = Array.new

	@reviewResults = Application.all(:conditions => [ "name ILIKE ?", "%#{@q}%" ], :order => [ :id.desc ], :record_type => @selectedRecordTypes) + Application.all(:conditions => [ "description ILIKE ?", "%#{@q}%" ], :order => [ :id.desc ], :record_type => @selectedRecordTypes)
	@testResults = Test.all(:conditions => [ "tests.name ILIKE ?", "%#{@q}%" ], :order => [ :id.desc ], Test.application.record_type => @selectedRecordTypes) + Test.all(:conditions => [ "tests.description ILIKE ?", "%#{@q}%" ], :order => [ :id.desc ], Test.application.record_type => @selectedRecordTypes)

	# Get VRLO custom results
	@vrloResults = Array.new
	@selectedRecordTypes.each do |rtid|
		rt = RecordType.get(rtid)
		if(rt.isLinked)
			vrlo = VRLinkedObject.getByKey(rt.linkedObjectKey)
			if(!vrlo.nil?)
				vrloSearchResults = nil
				begin
					vrloSearchResults = vrlo.doSearch(@q)
				rescue Exception => e
					vrloSearchResults = nil
					Rollbar.error(e, "Error doing VRLO search", {:query => @q, :vrlo_key => rt.linkedObjectKey})
				end

				if(!vrloSearchResults.nil? && vrloSearchResults.size > 0)
					@vrloResults << {:title => vrlo.vrlo_name, :results => vrloSearchResults}
				end
			end
		end
	end

	erb :search_results
end

- (Object) GET '/showdash/:dcid/?'



765
766
767
768
769
770
771
772
# File 'web.rb', line 765

get '/showdash/:dcid/?' do
	dcid = params[:dcid].to_i

	dc = DashConfig.get(dcid)
	dcid == 0 if(dc.nil?)

	instance_exec dcid, &show_dash
end

- (Object) GET '/tests/:tid/?'



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'routes/test.rb', line 70

get '/tests/:tid/?' do
	@test = Test.get(params[:tid])
	if(@test.nil?)
		@errstr = "Test not found"
		return erb :error 
	end

	@app = @test.application
	halt 401, (erb :unauth) if(!canViewReview?(@app.id))

	#By the time we get here, this only evals true for Admins or maybe Supers
	if(@app.isPrivate && !userAllowedForApp(@session[:uid], @app.id) && !userWarnedForTest?(@session[:uid], @test.id))
		if(params[:warned] == "true")
			markUserWarnedTest(@session[:uid], @test.id)
			redirect "/tests/#{@test.id}"
		else
			@tid = @test.id
			@aid = nil
			return erb :private_app_warning
		end
	end

	@vulnTypes = VulnType.getByRecordType(@app.record_type).sort{ |x,y| x.getLabel <=> y.getLabel}

	if(!@session[:errmsg].nil? && !@session[:errmsg].empty?)
		@error = @session[:errmsg]
		@session[:errmsg] = nil
	elsif(!@session[:sucmsg].nil? && !@session[:sucmsg].empty?)
		@success = @session[:sucmsg]
		@session[:sucmsg] = nil
	end

	if(!@session[:vrloAlerts].nil? && !@session[:vrloAlerts].empty?)
		@VRLOAlerts = @session[:vrloAlerts]
		@session[:vrloAlerts] = nil
	end

	@pageTitle = @app.name + " - " + @test.name
	@approver = nil
	if(@test.approved_by > 0)
		@approver = User.get(@test.approved_by)
	end

	@comments = Comment.commentsForTest(@test.id, @session[:uid], @session[:org])
	@unreadComments = 0
	@comments.each do |c|
		@unreadComments += 1 if(c.isUnseen?(session[:uid]))
	end

	if(!params[:fromNotif].nil?)
		@fromNotif = true
	end

	if(@app.recordType.isLinked && @app.isLinked?)
		if(@app.isLinked?)
			vrloInfo = @app.getVRLO.getTestAlerts(@app, @test, @session[:uid])
			if(!vrloInfo[:success])
				@errstr = "Error generating linked object information: #{vrloInfo[:errstr]}"
				return erb :error
			else
				@VRLOAlerts = vrloInfo[:alerts]
				
				@VRLOMenuItems = Array.new
				menuItems = vrloInfo[:customMenuItems]
				#check auth for each
				menuItems.each do |m|
					authOk = true
					if(!m[:authMethods].nil? && m[:authMethods].size > 0)
						m[:authMethods].each do |am|
							amMethod = am[0]
							amArgs = am[1]
							begin
								if(!amArgs.nil? && amArgs.size > 0)
									amResult = send(amMethod, amArgs)
								else
									amResult = send(amMethod)
								end
							rescue
								authOk = false
							end

							if(!amResult)
								authOk = false
							end
						end
					end

					if(authOk)
						@VRLOMenuItems << m
					end
				end
			end
		else
			@VRLOAlerts = nil
			@VRLOMenuItems = nil
		end
	else
		@VRLOAlerts = nil
		@VRLOMenuItems = nil
	end

	if(@test.provPassReq && !@test.provPass && !@test.complete)
		@provPassRequested = true
		ppReqAR = AuditRecord.last(:event_type => EVENT_TYPE::PROV_PASS_REQUEST, :target_a => @test.id)
		@ppReqUser = User.get(ppReqAR.actor)
		@ppReqTime = ppReqAR.event_at
		@ppReqJustif = ppReqAR.details_txt
	elsif(@test.provPass && @test.complete)
		@provPassApproved = true
		
		ppReqAR = AuditRecord.last(:event_type => EVENT_TYPE::PROV_PASS_REQUEST, :target_a => @test.id)
		@ppReqUser = User.get(ppReqAR.actor)
		@ppReqTime = ppReqAR.event_at
		@ppReqJustif = ppReqAR.details_txt

		ppApproveAR = AuditRecord.last(:event_type => EVENT_TYPE::PROV_PASS_APPROVE, :target_a => @test.id)
		@ppApprvUser = User.get(ppApproveAR.actor)
		@ppApprvTime = ppApproveAR.event_at
		@ppApprvNotes = ppApproveAR.details_txt
	end

	@pdf_on = false
	if(!getSetting('PDF_EXPORT_ON').nil? && getSetting('PDF_EXPORT_ON') == 'true')
		@pdf_on = true
	end

	erb :test_single
end

- (Object) GET '/tests/:tid/:vid/?'



1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
# File 'routes/test.rb', line 1000

get '/tests/:tid/:vid/?' do
	@vuln = Vulnerability.get(params[:vid])
	if(@vuln.nil?)
		@errstr = "Vuln not found"
		return erb :error 
	end
	@test = @vuln.test
	@app = @test.application
	halt 401, (erb :unauth) if(!canViewReview?(@app.id))

	@comments = Comment.commentsForVuln(@vuln.id, @session[:uid], @session[:org])
	@unreadComments = 0
	@comments.each do |c|
		@unreadComments += 1 if(c.isUnseen?(session[:uid]))
	end

	if(!params[:fromNotif].nil?)
		@fromNotif = true
	end

	if(!@session[:errmsg].nil? && !@session[:errmsg].empty?)
		@error = @session[:errmsg]
		@session[:errmsg] = nil
	end

	if(@vuln.vulntype == 0)
		@enabledSections = nil
	else
		@enabledSections = @vuln.vtobj.enabledSections
	end

	@pageTitle = @app.name + " - " + @test.name

	erb :vuln_single
end

- (Object) GET '/tests/:tid/:vid/:sid/delete/?'



1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
# File 'routes/test.rb', line 1390

get '/tests/:tid/:vid/:sid/delete/?' do
	@sect = Section.get(params[:sid])
	if(@sect.nil?)
		@errstr = "Section not found"
		return erb :error 
	end

	@vuln = @sect.vulnerability
	@test = @vuln.test
	@app = @test.application
	halt 401, (erb :unauth) if(!canViewReview?(@app.id))

	erb :vuln_sect_confirm_delete
end

- (Object) GET '/tests/:tid/:vid/:sid/download/?'



1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
# File 'routes/test.rb', line 1372

get '/tests/:tid/:vid/:sid/download/?' do
	@sect = Section.get(params[:sid])
	if(@sect.nil?)
		@errstr = "Section not found"
		return erb :error 
	end

	if(@sect.type != SECT_TYPE::PAYLOAD && @sect.type != SECT_TYPE::SSHOT)
		@errstr = "Can't download this section"
		return erb :error
	end

	fileData = Base64.decode64(@sect.body)

	attachment (@sect.fname.nil?) ? @sect.type_str : @sect.fname
	return fileData
end

- (Object) GET '/tests/:tid/:vid/delete/?'



1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
# File 'routes/test.rb', line 1326

get '/tests/:tid/:vid/delete/?' do
	@vuln = Vulnerability.get(params[:vid])
	if(@vuln.nil?)
		@errstr = "Vuln not found"
		return erb :error 
	end

	@test = @vuln.test
	@app = @test.application
	halt 401, (erb :unauth) if(!canViewReview?(@app.id))

	erb :vuln_confirm_delete
end

- (Object) GET '/tests/:tid/:vid/edit/?'



1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
# File 'routes/test.rb', line 1282

get '/tests/:tid/:vid/edit/?' do
	@vuln = Vulnerability.get(params[:vid])
	if(@vuln.nil?)
		@errstr = "Vuln not found"
		return erb :error 
	end

	@test = @vuln.test
	@app = @test.application
	halt 401, (erb :unauth) if(!canViewReview?(@app.id))

	@vulnTypes = VulnType.getByRecordType(@app.record_type).sort{ |x,y| x.getLabel <=> y.getLabel}

	erb :vuln_edit
end

- (Object) GET '/tests/:tid/:vid/fp?'



1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
# File 'routes/test.rb', line 1180

get '/tests/:tid/:vid/fp?' do
	@vuln = Vulnerability.get(params[:vid])
	if(@vuln.nil?)
		@errstr = "Vuln not found"
		return erb :error 
	end
	@test = @vuln.test
	halt 401, (erb :unauth) if(!canViewReview?(@test.application.id))

	@vuln.verified = true
	@vuln.falsepos = true
	@vuln.save

	redirect "/tests/#{params[:tid]}/#{params[:vid]}"
end

- (Object) GET '/tests/:tid/:vid/priority/:pri/?'



1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
# File 'routes/test.rb', line 1236

get '/tests/:tid/:vid/priority/:pri/?' do
	@vuln = Vulnerability.get(params[:vid])
	if(@vuln.nil?)
		@errstr = "Vuln not found"
		return erb :error 
	end
	@test = @vuln.test
	halt 401, (erb :unauth) if(!canViewReview?(@test.application.id))

	newPri = params[:pri].to_i

	if(@vuln.vulntype == 0)
		@vuln.priorityOverride = newPri
	else
		if(newPri != VulnType.get(@vuln.vulntype).priority)
			@vuln.priorityOverride = newPri
		else
			@vuln.priorityOverride = nil
		end
	end

	@vuln.save

	redirect "/tests/#{params[:tid]}/#{params[:vid]}"
end

- (Object) GET '/tests/:tid/:vid/unverify?'



1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
# File 'routes/test.rb', line 1164

get '/tests/:tid/:vid/unverify?' do
	@vuln = Vulnerability.get(params[:vid])
	if(@vuln.nil?)
		@errstr = "Vuln not found"
		return erb :error 
	end
	@test = @vuln.test
	halt 401, (erb :unauth) if(!canViewReview?(@test.application.id))

	@vuln.verified = false
	@vuln.falsepos = false
	@vuln.save

	redirect "/tests/#{params[:tid]}/#{params[:vid]}"
end

- (Object) GET '/tests/:tid/:vid/verify?'



1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
# File 'routes/test.rb', line 1196

get '/tests/:tid/:vid/verify?' do
	@vuln = Vulnerability.get(params[:vid])
	if(@vuln.nil?)
		@errstr = "Vuln not found"
		return erb :error 
	end
	@test = @vuln.test
	halt 401, (erb :unauth) if(!canViewReview?(@test.application.id))

	@vuln.verified = true
	@vuln.falsepos = false
	@vuln.save

	redirect "/tests/#{params[:tid]}/#{params[:vid]}"
end

- (Object) GET '/tests/:tid/cancelProvPassRequest/?'



737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
# File 'routes/test.rb', line 737

get '/tests/:tid/cancelProvPassRequest/?' do
	@test = Test.get(params[:tid])
	if(@test.nil?)
		@errstr = "Test not found"
		return erb :error 
	end

	@app = @test.application
	halt 401, (erb :unauth) if(!canViewReview?(@app.id))
	halt 401, (erb :unauth) if(contractor?)

	ar = AuditRecord.last(:event_type => EVENT_TYPE::PROV_PASS_REQUEST, :target_a_type => LINK_TYPE::TEST, :target_a => @test.id)
	halt 401, (erb :unauth) if(ar.actor != @session[:uid] && !canApproveProvPass?)

	erb :test_cancel_prov_pass
end

- (Object) GET '/tests/:tid/delete/?'



940
941
942
943
944
945
946
947
948
949
950
951
952
# File 'routes/test.rb', line 940

get '/tests/:tid/delete/?' do
	@test = Test.get(params[:tid])
	if(@test.nil?)
		@errstr = "Test not found"
		return erb :error 
	end

	@app = @test.application
	halt 401, (erb :unauth) if(!canViewReview?(@app.id))
	halt 401, (erb :unauth) if(!canDeleteTest?(@test.id))

	erb :test_confirm_delete
end

- (Object) GET '/tests/:tid/edit/?'



323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
# File 'routes/test.rb', line 323

get '/tests/:tid/edit/?' do
	@test = Test.get(params[:tid])
	if(@test.nil?)
		@errstr = "Test not found"
		return erb :error 
	end

	@app = @test.application
	halt 401, (erb :unauth) if(!canViewReview?(@app.id))

	@isContractorTest = ""
	@isContractorComplete = ""
	@isContractorPass = ""
		
	@isContractorTest = "checked" if(@test.contractor_test)
	
	@rev = User.get(@test.reviewer)
	@users = User.all(:active => true)

	@pageTitle = @app.name + " - " + @test.name

	erb :test_edit
end

- (Object) GET '/tests/:tid/fail/?'



428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
# File 'routes/test.rb', line 428

get '/tests/:tid/fail/?' do
	@test = Test.get(params[:tid])
	if(@test.nil?)
		@errstr = "Test not found"
		return erb :error 
	end

	@app = @test.application
	halt 401, (erb :unauth) if(!canViewReview?(@app.id) || !canFinalizeTest?(@test.id))

	@color = "#B40404"
	@newstatus = "failed"

	@disagree = false
	if(@test.is_pending && @test.pending_pass)
		@disagree = true
	end

	erb :test_status_conf
end

- (Object) GET '/tests/:tid/inprog/?'



449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
# File 'routes/test.rb', line 449

get '/tests/:tid/inprog/?' do
	@test = Test.get(params[:tid])
	if(@test.nil?)
		@errstr = "Test not found"
		return erb :error 
	end

	@app = @test.application
	halt 401, (erb :unauth) if(!canViewReview?(@app.id))

	@color = "#000"
	@newstatus = "in progress"

	erb :test_status_conf
end

- (Object) GET '/tests/:tid/pass/?'



402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
# File 'routes/test.rb', line 402

get '/tests/:tid/pass/?' do
	@test = Test.get(params[:tid])
	if(@test.nil?)
		@errstr = "Test not found"
		return erb :error 
	end

	@app = @test.application
	halt 401, (erb :unauth) if(!canViewReview?(@app.id) || !canFinalizeTest?(@test.id))

	@color = "#009933"
	@newstatus = "passed"

	@disagree = false
	if(@test.is_pending && !@test.pending_pass)
		@disagree = true
	end

	@informational = false
	if(@test.verified_vulns.count > 0)
		@informational = true
	end

	erb :test_status_conf
end

- (Object) GET '/tests/:tid/provPassApprove/?'



796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
# File 'routes/test.rb', line 796

get '/tests/:tid/provPassApprove/?' do
	@test = Test.get(params[:tid])
	if(@test.nil?)
		@errstr = "Test not found"
		return erb :error 
	end

	@app = @test.application
	halt 401, (erb :unauth) if(!canViewReview?(@app.id))
	halt 401, (erb :unauth) if(!canApproveProvPass?)

	ppReqAR = AuditRecord.last(:event_type => EVENT_TYPE::PROV_PASS_REQUEST, :target_a => @test.id)
	@ppReqUser = User.get(ppReqAR.actor)
	@ppReqTime = ppReqAR.event_at
	@ppReqJustif = ppReqAR.details_txt

	erb :test_prov_pass_approve
end

- (Object) GET '/tests/:tid/provPassRequest/?'



635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
# File 'routes/test.rb', line 635

get '/tests/:tid/provPassRequest/?' do
	@test = Test.get(params[:tid])
	if(@test.nil?)
		@errstr = "Test not found"
		return erb :error 
	end

	@app = @test.application
	halt 401, (erb :unauth) if(!canViewReview?(@app.id) || !canFinalizeTest?(@test.id))
	halt 401, (erb :unauth) if(contractor?)

	if(!@app.recordType.canBeProvPassed)
		@errstr = "This Application cannot be Provisionally Passed"
		return erb :error
	end

	approvers = Array.new
	approversUsers = Array.new
	User.all(:provPassApprover => true, :active => true).each do |u|
		if(getAllowedRTsForUser(u.id).include?(@app.record_type))
			approversUsers << u
		end
	end

	approversUsers.each do |u|
		approvers << u.name
	end

	@ppApproversStr = approvers.join(", ")

	erb :test_prov_pass_request
end

- (Object) GET '/tests/:tid/report/?'



899
900
901
902
903
904
905
906
907
908
909
910
# File 'routes/test.rb', line 899

get '/tests/:tid/report/?' do
	@test = Test.get(params[:tid])
	if(@test.nil?)
		@errstr = "Test not found"
		return erb :error 
	end

	halt 401, (erb :unauth) if(!canViewReview?(@test.application.id))

	attachment "Security Report for #{@test.application.name}.html"
	report_html @test.id
end

- (Object) GET '/tests/:tid/reportpdf/?'



924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
# File 'routes/test.rb', line 924

get '/tests/:tid/reportpdf/?' do
	@test = Test.get(params[:tid])
	if(@test.nil?)
		@errstr = "Test not found"
		return erb :error 
	end

	halt 401, (erb :unauth) if(!canViewReview?(@test.application.id))

	html = report_html(@test.id)
	kit = PDFKit.new(html, :margin_top => '0in', :margin_right => '0in', :margin_bottom => '0in', :margin_left => '0in')

	attachment "Security Report for #{@test.application.name}.pdf"
	kit.to_pdf
end

- (Object) GET '/tests/:tid/viewreport/?'



912
913
914
915
916
917
918
919
920
921
922
# File 'routes/test.rb', line 912

get '/tests/:tid/viewreport/?' do
	@test = Test.get(params[:tid])
	if(@test.nil?)
		@errstr = "Test not found"
		return erb :error 
	end

	halt 401, (erb :unauth) if(!canViewReview?(@test.application.id))

	return report_html @test.id
end

- (Object) GET '/tests/:tid/viewTypes/?'



986
987
988
989
990
991
992
993
994
995
996
997
998
# File 'routes/test.rb', line 986

get '/tests/:tid/viewTypes/?' do
	@test = Test.get(params[:tid])

	if(@test.nil? || !canViewReview?(@test.application.id))
		@errstr = "Cannot access test"
		erb :error
	end

	@app = @test.application
	@vulnTypes = VulnType.getByRecordType(@app.record_type).sort{ |x,y| x.getLabel <=> y.getLabel}

	erb :test_preview_vts
end

- (Object) GET '/tests/:tid/xmlup/?'



225
226
227
228
229
230
231
232
233
234
235
236
# File 'routes/test.rb', line 225

get '/tests/:tid/xmlup/?' do
	@test = Test.get(params[:tid])
	if(@test.nil?)
		@errstr = "Test not found"
		return erb :error 
	end

	@app = @test.application
	halt 401, (erb :unauth) if(!canViewReview?(@app.id))

	erb :test_importxml
end

- (Object) GET '/tests/doClipboard/pasteToTest/:tid/?'



1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
# File 'routes/test.rb', line 1482

get '/tests/doClipboard/pasteToTest/:tid/?' do
	@test = Test.get(params[:tid])
	@app = @test.application
	halt 401, (erb :unauth) if(!canViewReview?(@app.id))

	if(@session[:clipboard].nil?)
		redirect "/tests/#{@test.id}"
	else
		if(@session[:clipboard][:type] == LINK_TYPE::VULN)
			vulnToCopy = Vulnerability.get(@session[:clipboard][:id])
			vulnToCopyAttribs = vulnToCopy.attributes
			vulnToCopyAttribs.delete(:id)
			
			newVuln = @test.vulnerabilities.create(vulnToCopyAttribs)

			vulnToCopy.sections.each do |s|
				sa = s.attributes
				sa.delete(:id)
				newVuln.sections.create(sa)
			end
		elsif(@session[:clipboard][:type] == LINK_TYPE::TEST)
			testToCopy = Test.get(@session[:clipboard][:id])

			testToCopy.vulnerabilities.each do |v|
				va = v.attributes
				va.delete(:id)
				
				newVuln = @test.vulnerabilities.create(va)

				v.sections.each do |s|
					sa = s.attributes
					sa.delete(:id)
					newVuln.sections.create(sa)
				end
			end
		end

		@session[:clipboard] = nil
		redirect "/tests/#{@test.id}"
	end
end

- (Object) GET '/tests/doClipboard/test/:tid/?'



1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
# File 'routes/test.rb', line 1453

get '/tests/doClipboard/test/:tid/?' do
	@test = Test.get(params[:tid])
	@app = @test.application
	halt 401, (erb :unauth) if(!canViewReview?(@app.id))

	if(!@session[:clipboard].nil? && @session[:clipboard][:type] == LINK_TYPE::TEST && @session[:clipboard][:id] == @test.id)
		@session[:clipboard] = nil
		return 204
	else
		@session[:clipboard] = {:type => LINK_TYPE::TEST, :id => @test.id}
		return 201
	end
end

- (Object) GET '/tests/doClipboard/vuln/:vid/?'



1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
# File 'routes/test.rb', line 1467

get '/tests/doClipboard/vuln/:vid/?' do
	@vuln = Vulnerability.get(params[:vid])
	@test = @vuln.test
	@app = @test.application
	halt 401, (erb :unauth) if(!canViewReview?(@app.id))

	if(!@session[:clipboard].nil? && @session[:clipboard][:type] == LINK_TYPE::VULN && @session[:clipboard][:id] == @vuln.id)
		@session[:clipboard] = nil
		return 204
	else
		@session[:clipboard] = {:type => LINK_TYPE::VULN, :id => @vuln.id}
		return 201
	end
end

- (Object) GET '/tests/newfromapp/:aid/?'



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
# File 'routes/test.rb', line 10

get '/tests/newfromapp/:aid/?' do
	@app = Application.get(params[:aid])
	if(@app.nil?)
		@errstr = "Application not found"
		return erb :error 
	end

	halt 401, (erb :unauth) if(!canViewReview?(@app.id))

	#See if theres already an active test for this app
	@app.tests.each do |ct|
		if(!ct.complete)
			#found one in progress
			redirect "/tests/#{ct.id}"
			return
		end
	end

	num = (@app.tests.count+1).to_s
	u = User.get(session[:uid])
	test = @app.tests.new(:reviewer => session[:uid], :name => "Test #{num}", :org_created => u.org)
	
	if(contractor?)
		test.contractor_test = true
	end

	ownerChange = false
	if(@app.owner.nil? || @app.owner == 0)
		@app.owner = session[:uid]
		ownerChange = true
	end

	@app.save
	logAudit(EVENT_TYPE::TEST_CREATE, LINK_TYPE::TEST, test.id)
	logAudit(EVENT_TYPE::TEST_REVIEWER_ASSIGNED, LINK_TYPE::TEST, test.id, {:userName => u.name})
	if(ownerChange)
		logAudit(EVENT_TYPE::APP_OWNER_ASSIGN, LINK_TYPE::APPLICATION, @app.id, {:userName => u.name})
	end

	if(@app.recordType.isLinked && @app.isLinked?)
		vrlo = @app.getVRLO
		begin
			vrloResult = vrlo.doNewTestActions(@app, test, @session[:uid])
		rescue Exception => e
			Rollbar.error(e, "Unable to perform VRLO New Test Actions", {:vrlo_key => vrlo.vrlo_key, :aid => @app.id, :vrlo_eid => @app.linkId})
			vrloResult = {:success => false, :errstr => "Exception while performing Linked Object actions"}
		end

		if(!vrloResult[:success])
			session[:errmsg] = "<b>Error:</b> Error performing linked object actions - #{vrloResult[:errstr]}"
		end

		if(!vrloResult[:alerts].nil?)
			session[:vrloAlerts] = vrloResult[:alerts]
		end
	end

	redirect "/tests/#{test.id}"
end

- (Object) GET '/userdash/?'



1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
# File 'web.rb', line 1027

get '/userdash/?' do
	month = params['m'].to_i
	year = params['y'].to_i

	if(month.nil? || year.nil? || year < 2014 || year > 2025 || month < 1 || month > 12)
		@date = Date.today.at_beginning_of_month
	else
		@date = Date.new(year, month, 1)
	end

	@user = User.get(session[:uid])

	userAlloc = MonthlyAllocation.allocationForUser(@user.id, month=@date.month, year=@date.year)
	if(userAlloc.nil?)
		@alloc = 0
		@allocNil = true
		@autoSet = false
	else
		@alloc = userAlloc.allocation
		@autoSet = userAlloc.wasAutoSet
		@allocNil = false
	end

	@allocApps = (((@user.allocCoeff.to_f)/12.0)*(@alloc.to_f/100.0)).round

	@numTests = 0
	@appsTouched = Array.new
	endDate = @date >> 1
	Test.all(:reviewer => @user.id, :complete => true, :closed_at => (@date..endDate)).each do |t|
		@numTests += 1
		if(!@appsTouched.include?(t.application_id))
			@appsTouched << t.application_id
		end
	end

	@pbWidth = 0
	@allocCompletionPct = 0
	if(@appsTouched.size > 0)
		@allocCompletionPct = ((@appsTouched.size.to_f / @allocApps.to_f)*100)
		if(@appsTouched.size > 0 && @allocApps == 0)
			@pbWidth = 100
		else
			@pbWidth = @allocCompletionPct.round
			@pbWidth = 100 if @pbWidth > 100
		end
	end

	## LIFETIME STATS ##
	@lifetimeTests = 0
	@lifetimePass = 0
	@lifetimeFail = 0
	@lifetimeAppsTouched = Array.new
	@lifetimeVulns = Array.new

	@lifetimeMaxTestTime = 0
	@lifetimeMaxTest = nil
	@lifetimeMinTestTime = 0
	@lifetimeMinTest = nil

	lifetimeTotalTestDays = 0

	Test.all(:reviewer => @user.id, :complete => true).each do |t|
		@lifetimeTests += 1
		if(t.pass)
			@lifetimePass += 1
		else
			@lifetimeFail += 1
		end

		if(!@lifetimeAppsTouched.include?(t.application_id))
			@lifetimeAppsTouched << t.application_id
		end

		@lifetimeVulns.push(*t.vulnerabilities)

		if(!t.closed_at.nil? && !t.created_at.nil?)
			testDays = t.closed_at - t.created_at
			lifetimeTotalTestDays += testDays
			if(testDays > @lifetimeMaxTestTime)
				@lifetimeMaxTestTime = testDays
				@lifetimeMaxTest = t
			end
			if(testDays < @lifetimeMinTestTime || @lifetimeMinTestTime == 0)
				@lifetimeMinTestTime = testDays
				@lifetimeMinTest = t
			end
		end

		@lifetimeTTRAvg = (lifetimeTotalTestDays.to_f / @lifetimeTests.to_f)
	end

	if(@lifetimeTests < 1)
		@lifetimePassPct = 0
		@lifetimeFailPct = 0
		@lifetimeTTRAvg = 0
	else
		@lifetimePassPct = (@lifetimePass.to_f / @lifetimeTests.to_f)*100
		@lifetimeFailPct = (@lifetimeFail.to_f / @lifetimeTests.to_f)*100
	end

	#top 5 vuln types and counts
	vulnTypeCounts = Array.new(VulnType.count()+1, 0)
	@lifetimeVulns.each do |v|
		next if(v.vulntype == 0)
		vulnTypeCounts[v.vulntype] += 1
	end

	sortedIdx = vulnTypeCounts.map.with_index.sort{|x, y| y <=> x}.map(&:last)[0..4]
	@topVulns = Array.new
	@maxTopVulnCount = vulnTypeCounts[sortedIdx[0]]
	sortedIdx.each do |i|
		next if(i < 1)
		next if vulnTypeCounts[i] == 0
		@topVulns << {:vtid => i, :vt => h(VulnType.get(i).name), :count => vulnTypeCounts[i]}
	end

	erb :userdash
end

- (Object) GET '/usersettings'



924
925
926
927
928
929
930
931
932
933
934
935
936
937
# File 'web.rb', line 924

get '/usersettings' do
	@user = User.get(session[:uid])

	userAlloc = MonthlyAllocation.allocationForUser(@user.id)
	if(userAlloc.nil?)
		@alloc = 0
	else
		@alloc = userAlloc.allocation
	end

	@dashConfigs = DashConfig.all(:active => true)

	erb :usersettings
end

- (Object) GET '/usersettings/auth/?'



981
982
983
984
985
# File 'web.rb', line 981

get '/usersettings/auth/?' do
	@user = User.get(session[:uid])

	erb :usersettings_auth
end

- (Object) GET '/vulns/starredVulns/?'



1524
1525
1526
1527
1528
# File 'routes/test.rb', line 1524

get '/vulns/starredVulns/?' do
	@vulns = Vulnerability.all(:starred => true, :order => [:id.desc])

	erb :vuln_starred_list
end

- (Object) GET /geo/:geo/?



774
775
776
777
# File 'web.rb', line 774

get "/geo/:geo/?" do
	session[:geo] = params[:geo].to_i
	redirect "/"
end

- (Object) GET /logout/?



190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'routes/auth.rb', line 190

get "/logout/?" do
	session[:logged_in] = false
	session[:uid] = nil
	session[:org] = nil
	session[:username] = nil
	session[:email] = nil
	session[:name] = nil
	session[:clipboard] = nil
	session[:geo] = nil
	session.clear

	session[:logout_complete] = true
	redirect "/login"
end

- (Object) GET /prefetchBH/?

Endpoint to prefetch typeahead data for Bloodhound (used for search bar). Prefetch returns the most recent 250 Applications (by creation date). For matches not found in prefetch data, search will hit the /remoteBH endpoint. Return format is JSON.

Web Route:

  • /prefetchBH



1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
# File 'web.rb', line 1151

get "/prefetchBH/?" do
	if(reports_only?)
		return "[]"
	end

	allowedRTs = getAllowedRTsForUser(@session[:uid])
	apps = Array.new

	Application.all(:record_type => allowedRTs, :order => [ :id.desc ], :limit => 250).each do |a|
		if(a.isPrivate)
			next if(!a.allow_UIDs.nil? && !a.allow_UIDs.include?(@session[:uid]))
		end
		apps << {"name" => a.name, :id => a.id}.to_json
	end

	return "[#{apps.join(",")}]"
end

- (Object) GET /saml/login/?



107
108
109
110
111
# File 'routes/auth.rb', line 107

get "/saml/login/?" do
    settings = saml_settings
    request = OneLogin::RubySaml::Authrequest.new
    redirect request.create(settings)
end

- (Object) GET /viewAllNotifs/?



904
905
906
907
908
909
# File 'web.rb', line 904

get "/viewAllNotifs/?" do
	@notifs = Notification.allForUser(session[:uid])
	Notification.markAllUserRead(session[:uid])

	erb :view_all_notifs
end

- (String) getMonitorCausedByString(ma)

Define a string to represent the action that caused the monitor EVENT_TYPE to be logged. This string should be based on information in the AuditRecord

Parameters:

Returns:

  • (String)

    String representation of what caused this event to be recorded



23
24
25
26
# File 'routes/monitors.rb', line 23

def getMonitorCausedByString(ma)
	# Define this for all EVENT_TYPEs that are in MONITOR_EVENT_TYPES
	# See documentation on custom interfaces to learn more
end

- (String) getMonitorSuspectString(ma)

Get a string representing the actor/suspect action that caused an event to be recorded

Parameters:

Returns:

  • (String)

    String representation of who caused this event to be recorded



32
33
34
35
# File 'routes/monitors.rb', line 32

def getMonitorSuspectString(ma)
	# Define this for all EVENT_TYPEs that are in MONITOR_EVENT_TYPES
	# See documentation on custom interfaces to learn more
end

- (String) getMonitorTargetString(ma)

Get a string representing the target that was modified/etc causing the event to be recorded

Parameters:

Returns:

  • (String)

    String representation of what the event recorded acted on



41
42
43
44
# File 'routes/monitors.rb', line 41

def getMonitorTargetString(ma)
	# Define this for all EVENT_TYPEs that are in MONITOR_EVENT_TYPES
	# See documentation on custom interfaces to learn more
end

- (String) getMonitorTypeString(mt)

Define a string to represent the action each monitor EVENT_TYPE is tracking

Parameters:

Returns:

  • (String)

    String representation of event type that was recorded



13
14
15
16
# File 'routes/monitors.rb', line 13

def getMonitorTypeString(mt)
	# Define this for all EVENT_TYPEs that are in MONITOR_EVENT_TYPES
	# See documentation on custom interfaces to learn more
end

- (Object) NOT_FOUND



225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'web.rb', line 225

not_found do
	uinfo = {
		:id => session[:uid],
		:username => session[:username],
		:email => session[:email]
	}

	Rollbar.scoped({:person => uinfo}) do
		Rollbar.warning("404 - Route Not Found", {:route => request.path_info, :referrer => request.referrer})
	end
	
	@errstr = "Vulnreport was unable to find a route to handle this request. The error has been logged and an alert has been sent. It will be debugged ASAP."
	erb :error
end

- (Hash{String => Boolean}, ...) parseFlags(param)

Parse the app flags parameter given in report URL (formed by #form_flagstring)

Parameters:

  • param (String)

    Flags chosen string formed by form_flagstring

Returns:

  • (Hash{String => Boolean}, String)

    Hash with keys of flags to boolean representing selection,

  • (Array<Integer>, String)

    Array of integers representing selected Flags (IDs) and String of chosen flags for UI



111
112
113
114
115
116
117
118
119
120
121
# File 'routes/reports.rb', line 111

def parseFlags(param)
	if(param.nil? || param.downcase == "all")
		selectedFlags = [-1]
		uiStr = "all"
	else
		selectedFlags = param.split("|").map{|n| n.to_i}
		uiStr = "flagged"
	end

	return selectedFlags, uiStr
end

- (String) parseInterval(param, allowed, default = "month")

Parse the reporting interval for a report given in report URL

Parameters:

  • param (String)

    The interval parameter

  • allowed (Array<String>)

    Allowed intervals

  • default (String) (defaults to: "month")

    Default interval to use if param is invalid

Returns:

  • (String, String)

    The parsed parameter, Capitalized interval for UI



100
101
102
103
104
# File 'routes/reports.rb', line 100

def parseInterval(param, allowed, default="month")
	param = default unless allowed.map{|i| i.downcase}.include?(param)
	
	return param, param.capitalize
end

- (DateTime, String) parsePeriod(period, defaultStart = nil, defaultEnd = nil)

Parse the date period for a report given in report URL (formed by #form_datestring)

Parameters:

  • period (String)

    Period string formed by form_datestring, e.g. “03-01-2016…04-01-2016”

  • defaultStart (DateTime) (defaults to: nil)

    default start date to use if period is “default”

  • defaultEnd (DateTime) (defaults to: nil)

    default end date to use if period is “default”

Returns:

  • (DateTime, DateTime, String)

    start date (DateTime), end date (DateTime), and string representing the period for the UI (String)



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'routes/reports.rb', line 72

def parsePeriod(period, defaultStart = nil, defaultEnd = nil)
	startdate = nil
	enddate = nil
	periodString = nil

	if(period == "default")
		startdate = (defaultStart.nil?) ? Date.today.at_beginning_of_month.prev_month.to_datetime : defaultStart
		enddate = (defaultEnd.nil?) ?  Date.today.to_datetime.end_of_day : defaultEnd
		periodString = startdate.strftime('%m-%d-%Y') + " to " + enddate.strftime('%m-%d-%Y')
	elsif(period == "all")
		startdate = DateTime.strptime("01-01-2012", '%m-%d-%Y')
		enddate = Date.today.to_datetime+1
		periodString = "All"
	else
		startdate = DateTime.strptime(period.split("...")[0], '%m-%d-%Y')
		enddate = DateTime.strptime(period.split("...")[1], '%m-%d-%Y').end_of_day
		periodString = startdate.strftime('%m-%d-%Y') + " to " + enddate.strftime('%m-%d-%Y')
	end

	return startdate, enddate, periodString
end

- (Array<Integer>) parseRt(param, default = nil)

Parse the Record Types parameter given in report URL (formed by #form_rtstring) and validate user permission to access those RecordTypes

Parameters:

  • param (String)

    Record Types chosen string formed by form_rtstring e.g. 1|3|4

  • default (Array<Integer>) (defaults to: nil)