Class: Application

Inherits:
Object
  • Object
show all
Includes:
DataMapper::Resource
Defined in:
models/application.rb

Overview

An application reviewed in Vulnreport. In general, an Application in Vulnreport represents an SR cycle.

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from DataMapper::Resource

#make_dirty

Class Method Details

+ (String) add_emails(repository = nil)

Returns CSV of additional email addresses to copy on reports

Returns:

  • (String)

    CSV of additional email addresses to copy on reports



21
# File 'models/application.rb', line 21

property :add_emails,	String, :length => 500

+ (Array<Integer>) allow_UIDs(repository = nil)

Returns IDs of Users allowed to view if private (or override other security settings if not)

Returns:

  • (Array<Integer>)

    IDs of Users allowed to view if private (or override other security settings if not)



25
# File 'models/application.rb', line 25

property :allow_UIDs,	CommaSeparatedList

+ (Array<Application>) allWithFlags(selectedFlags, params = {})

Get Apps with any of the given flags and match given parameters. This method passes through to Application.all with additional parameters to properly filter by flag

Parameters:

  • selectedFlags (Array)

    Array of flag IDs to filter by

  • params (Hash) (defaults to: {})

    Additional params to pass to Application.all

Returns:



276
277
278
279
280
281
282
# File 'models/application.rb', line 276

def self.allWithFlags(selectedFlags, params={})
	if(selectedFlags.include?(-1))
		return all(params)
	else
		return all({flags.id => selectedFlags}.merge(params))
	end
end

+ (Array<Application>) countWithFlags(selectedFlags, params = {})

Count Applications that have the given flags and match given parameters. This method passes through to Application.count with additional parameters to properly filter by flag

Parameters:

  • selectedFlags (Array<Integer>)

    Flags to filter by

  • params (Hash) (defaults to: {})

    Additional params to pass to Application.count

Returns:

  • (Array<Application>)

    Number of matching Applications



290
291
292
# File 'models/application.rb', line 290

def self.countWithFlags(selectedFlags, params={})
	return allWithFlags(selectedFlags, params.merge({:fields => [:id]})).size
end

+ (DateTime) created_at(repository = nil)

Returns Date/Time application created (DM Handled)

Returns:

  • (DateTime)

    Date/Time application created (DM Handled)



17
# File 'models/application.rb', line 17

property :created_at, 	DateTime

+ (String) description(repository = nil)

Returns Application description

Returns:

  • (String)

    Application description



16
# File 'models/application.rb', line 16

property :description,	Text

+ (GEO) geo(repository = nil)

Returns Geo application is in

Returns:

  • (GEO)

    Geo application is in



27
# File 'models/application.rb', line 27

property :geo,			Integer

+ (Application) getByLinkId(eid)

Return Application linked to given VRLinkedObject extenral ID

Parameters:

  • eid (String)

    EID

Returns:

  • (Application)

    Application linked to given object ID



36
37
38
39
40
# File 'models/application.rb', line 36

def self.getByLinkId(eid)
	link = Link.first(:fromType => LINK_TYPE::APPLICATION, :toType => LINK_TYPE::VRLO, :toId => eid)
	return nil if link.nil?
	return get(link.fromId)
end

+ (Boolean) global(repository = nil)

Returns True if app is marked as global (any user can view)

Returns:

  • (Boolean)

    True if app is marked as global (any user can view)



23
# File 'models/application.rb', line 23

property :global,		Boolean, :default => false

+ (Integer) id(repository = nil)

Returns Primary Key

Returns:

  • (Integer)

    Primary Key



13
# File 'models/application.rb', line 13

property :id,			Serial

+ (Boolean) isPrivate(repository = nil)

Returns True if app is marked as private (only specified users can view)

Returns:

  • (Boolean)

    True if app is marked as private (only specified users can view)



24
# File 'models/application.rb', line 24

property :isPrivate,	Boolean, :default => false

+ (String) name(repository = nil)

Returns Application name

Returns:

  • (String)

    Application name



15
# File 'models/application.rb', line 15

property :name,			String, :length => 100

+ (Integer) org_created(repository = nil)

Returns ID of Organization of User that created this Application

Returns:



20
# File 'models/application.rb', line 20

property :org_created,	Integer, :default => 1

+ (Integer) owner(repository = nil)

Returns ID of User owner of this test

Returns:

  • (Integer)

    ID of User owner of this test



19
# File 'models/application.rb', line 19

property :owner,		Integer

+ (Integer) record_type(repository = nil)

Returns RecordType ID

Returns:



14
# File 'models/application.rb', line 14

property :record_type,	Integer, :required => true, :default => 0

+ (DateTime) updated_at(repository = nil)

Returns Date/Time application last updated (DM Handled)

Returns:

  • (DateTime)

    Date/Time application last updated (DM Handled)



18
# File 'models/application.rb', line 18

property :updated_at, 	DateTime

Instance Method Details

- (String) add_emails

Returns CSV of additional email addresses to copy on reports

Returns:

  • (String)

    CSV of additional email addresses to copy on reports



21
# File 'models/application.rb', line 21

property :add_emails,	String, :length => 500

- (String) add_emails=(value)

Returns CSV of additional email addresses to copy on reports

Returns:

  • (String)

    CSV of additional email addresses to copy on reports



21
# File 'models/application.rb', line 21

property :add_emails,	String, :length => 500

- (Array<Integer>) allow_UIDs

Returns IDs of Users allowed to view if private (or override other security settings if not)

Returns:

  • (Array<Integer>)

    IDs of Users allowed to view if private (or override other security settings if not)



25
# File 'models/application.rb', line 25

property :allow_UIDs,	CommaSeparatedList

- (Array<Integer>) allow_UIDs=(value)

Returns IDs of Users allowed to view if private (or override other security settings if not)

Returns:

  • (Array<Integer>)

    IDs of Users allowed to view if private (or override other security settings if not)



25
# File 'models/application.rb', line 25

property :allow_UIDs,	CommaSeparatedList

- (Boolean) canPassToContractor?

Returns True if this application can be passed to a contractor

Returns:

  • (Boolean)

    True if this application can be passed to a contractor



233
234
235
236
237
238
239
# File 'models/application.rb', line 233

def canPassToContractor?
	if(record_type.nil? || record_type == 0)
		return false
	end

	return RecordType.get(record_type).canBePassedToCon
end

- (DateTime) created_at

Returns Date/Time application created (DM Handled)

Returns:

  • (DateTime)

    Date/Time application created (DM Handled)



17
# File 'models/application.rb', line 17

property :created_at, 	DateTime

- (DateTime) created_at=(value)

Returns Date/Time application created (DM Handled)

Returns:

  • (DateTime)

    Date/Time application created (DM Handled)



17
# File 'models/application.rb', line 17

property :created_at, 	DateTime

- (String) description

Returns Application description

Returns:

  • (String)

    Application description



16
# File 'models/application.rb', line 16

property :description,	Text

- (String) description=(value)

Returns Application description

Returns:

  • (String)

    Application description



16
# File 'models/application.rb', line 16

property :description,	Text

- (Array<Integer>) flagIds

Returns IDs of all Flags associated with this Application

Returns:

  • (Array<Integer>)

    IDs of all Flags associated with this Application



243
244
245
# File 'models/application.rb', line 243

def flagIds
	return self.flags.map{|f| f.id}
end

- (GEO) geo

Returns Geo application is in

Returns:

  • (GEO)

    Geo application is in



27
# File 'models/application.rb', line 27

property :geo,			Integer

- (GEO) geo=(value)

Returns Geo application is in

Returns:

  • (GEO)

    Geo application is in



27
# File 'models/application.rb', line 27

property :geo,			Integer

- (String) geoIcon

Get icon name of flag for Application's geo

Returns:

  • (String)

    flag icon name



135
136
137
138
139
140
141
142
143
# File 'models/application.rb', line 135

def geoIcon
	if(geo == GEO::USA)
		return "flag-icon-us"
	elsif(geo == GEO::JP)
		return "flag-icon-jp"
	else
		return "flag-icon-us"
	end
end

- (String) geoString

Get string of Application's geo

Returns:

  • (String)

    Application's geo



148
149
150
151
152
153
154
155
156
# File 'models/application.rb', line 148

def geoString
	if(geo == GEO::USA)
		return "USA"
	elsif(geo == GEO::JP)
		return "Japan"
	else
		return "USA"
	end
end

- (VRLinkedObject) getVRLO

Get the VRLinkedObject subclass for this application based on RecordType

Returns:

  • (VRLinkedObject)

    Application's RecordType's LinkedObject class or nil if there is none



183
184
185
186
187
188
189
190
191
192
193
194
# File 'models/application.rb', line 183

def getVRLO
	if(record_type.nil? || record_type == 0)
		return nil
	end

	rt = RecordType.get(record_type)
	if(!rt.isLinked)
		return nil
	end

	return VRLinkedObject.getByKey(rt.linkedObjectKey)
end

- (Boolean) global

Returns True if app is marked as global (any user can view)

Returns:

  • (Boolean)

    True if app is marked as global (any user can view)



23
# File 'models/application.rb', line 23

property :global,		Boolean, :default => false

- (Boolean) global=(value)

Returns True if app is marked as global (any user can view)

Returns:

  • (Boolean)

    True if app is marked as global (any user can view)



23
# File 'models/application.rb', line 23

property :global,		Boolean, :default => false

- (Integer) id

Returns Primary Key

Returns:

  • (Integer)

    Primary Key



13
# File 'models/application.rb', line 13

property :id,			Serial

- (Integer) id=(value)

Returns Primary Key

Returns:

  • (Integer)

    Primary Key



13
# File 'models/application.rb', line 13

property :id,			Serial

- (Boolean) isLinked?

Check if Application is linked by a VRLinkedObject and has a linked ID

Returns:

  • (Boolean)

    true if linked, false otherwise



45
46
47
48
49
50
51
52
# File 'models/application.rb', line 45

def isLinked?
	links = Link.all(:fromType => LINK_TYPE::APPLICATION, :fromId => self.id, :toType => LINK_TYPE::VRLO)
	if(!links.nil? && links.size > 0)
		return true
	else
		return false
	end
end

- (Boolean) isPrivate

Returns True if app is marked as private (only specified users can view)

Returns:

  • (Boolean)

    True if app is marked as private (only specified users can view)



24
# File 'models/application.rb', line 24

property :isPrivate,	Boolean, :default => false

- (Boolean) isPrivate=(value)

Returns True if app is marked as private (only specified users can view)

Returns:

  • (Boolean)

    True if app is marked as private (only specified users can view)



24
# File 'models/application.rb', line 24

property :isPrivate,	Boolean, :default => false

- (String) lastStatus

Get (unformatted/code) status of Application's most recent Test

Returns:

  • (String)

    most recent test status (unformatted)



99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'models/application.rb', line 99

def lastStatus
	lastStatus = nil
	if(self.tests.nil? || self.tests.size == 0)
		lastStatus = "notests"
	elsif(self.tests.last.complete && self.tests.last.pass)
		lastStatus = "pass"
	elsif(self.tests.last.complete && !self.tests.last.pass)
		lastStatus = "fail"
	else
		lastStatus = "inprog"
	end

	return lastStatus
end

- (String) lastStatusFormatted

Get formatted status of Application's most recent Test

Returns:

  • (String)

    most recent test status (formatted HTML string)



117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'models/application.rb', line 117

def lastStatusFormatted
	lastStatus = nil
	if(self.tests.nil? || self.tests.size == 0)
		lastStatus = "No Tests"
	elsif(self.tests.last.complete && self.tests.last.pass)
		lastStatus = '<span style="color:#009933;">Pass</span>'
	elsif(self.tests.last.complete && !self.tests.last.pass)
		lastStatus = '<span style="color:#B40404;">Fail</span>'
	else
		lastStatus = "In Progress"
	end

	return lastStatus
end

- (Object) linkedObjectInfoPanel(uid, params, env)



222
223
224
225
226
227
228
229
# File 'models/application.rb', line 222

def linkedObjectInfoPanel(uid, params, env)
	vrlo = self.getVRLO
	if(vrlo.nil?)
		return ""
	end

	return vrlo.getLinkedObjectInfoPanel(self, uid, params, env)
end

- (String) linkedObjectText

Using the VRLinkedObject subclass for this application based on RecordType, get the name or text representation of the object that this application is linked to.

Returns:

  • (String)

    The text, or nil if there is none



213
214
215
216
217
218
219
220
# File 'models/application.rb', line 213

def linkedObjectText
	vrlo = self.getVRLO
	if(vrlo.nil?)
		return nil
	end

	return vrlo.getLinkedObjectText(self)
end

- (String) linkedObjectURL

Using the VRLinkedObject subclass for this application based on RecordType, get the URL of the object that this application is linked to.

Returns:

  • (String)

    The URL, or nil if there is none



200
201
202
203
204
205
206
207
# File 'models/application.rb', line 200

def linkedObjectURL
	vrlo = self.getVRLO
	if(vrlo.nil?)
		return nil
	end

	return vrlo.getLinkedObjectURL(self)
end

- (String) linkId

Get the EID of the object Application is linked to

Returns:

  • (String)

    EID of linked object



57
58
59
60
61
# File 'models/application.rb', line 57

def linkId
	link = Link.first(:fromType => LINK_TYPE::APPLICATION, :fromId => self.id, :toType => LINK_TYPE::VRLO)
	return nil if link.nil?
	return link.toId
end

- (String) name

Returns Application name

Returns:

  • (String)

    Application name



15
# File 'models/application.rb', line 15

property :name,			String, :length => 100

- (String) name=(value)

Returns Application name

Returns:

  • (String)

    Application name



15
# File 'models/application.rb', line 15

property :name,			String, :length => 100

- (Integer) org_created

Returns ID of Organization of User that created this Application

Returns:



20
# File 'models/application.rb', line 20

property :org_created,	Integer, :default => 1

- (Integer) org_created=(value)

Returns ID of Organization of User that created this Application

Returns:



20
# File 'models/application.rb', line 20

property :org_created,	Integer, :default => 1

- (Integer) owner

Returns ID of User owner of this test

Returns:

  • (Integer)

    ID of User owner of this test



19
# File 'models/application.rb', line 19

property :owner,		Integer

- (Integer) owner=(value)

Returns ID of User owner of this test

Returns:

  • (Integer)

    ID of User owner of this test



19
# File 'models/application.rb', line 19

property :owner,		Integer

- (String) ownerName

Returns name of owner user

Returns:

  • (String)

    name of owner user



88
89
90
91
92
93
94
# File 'models/application.rb', line 88

def ownerName
	if(self.owner.nil? || self.owner == 0)
		return "Unassigned"
	else
		return ownerUser.name
	end
end

- (User) ownerUser

Return User object of current owner

Returns:



78
79
80
81
82
83
84
# File 'models/application.rb', line 78

def ownerUser
	if(self.owner.nil? || self.owner == 0)
		return nil
	else
		return User.get(self.owner)
	end
end

- (Integer) record_type

Returns RecordType ID

Returns:



14
# File 'models/application.rb', line 14

property :record_type,	Integer, :required => true, :default => 0

- (Integer) record_type=(value)

Returns RecordType ID

Returns:



14
# File 'models/application.rb', line 14

property :record_type,	Integer, :required => true, :default => 0

- (RecordType) recordType

Get Application's RecordType

Returns:



161
162
163
164
165
166
167
# File 'models/application.rb', line 161

def recordType
	if(record_type.nil? || record_type == 0)
		return nil
	end

	return RecordType.get(record_type)
end

- (String) recordTypeName

Get name of Application's RecordType

Returns:

  • (String)

    Application's RecordType name



172
173
174
175
176
177
178
# File 'models/application.rb', line 172

def recordTypeName
	if(record_type.nil? || record_type == 0)
		return "Unknown"
	end

	return RecordType.get(record_type).name
end

- (Integer) totalvulns

Get the total number of Vulnerability objects attached to Tests attached to Application

Returns:

  • (Integer)

    total number of vulns



66
67
68
69
70
71
72
73
# File 'models/application.rb', line 66

def totalvulns
	count = 0
	tests.each do |t|
		count += t.vulnerabilities.count
	end

	return count
end

- (String) typeIcons

Get HTML formatted string of icons representing Application's flags

Returns:

  • (String)

    HTML of icons



250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
# File 'models/application.rb', line 250

def typeIcons
	flagIcons = Array.new
	self.flags.each do |f|
		if(!f.icon.nil? && !f.icon.strip.empty?)
			flagIcons << f
		end
	end

	str = ""
	flagIcons.each do |f|
		if(f.description.nil? || f.description.strip.empty?)
			str += "<i class=\"fa #{f.icon}\" rel=\"tooltip\" title=\"#{f.name}\"></i> "
		else
			str += "<i class=\"fa #{f.icon}\" rel=\"tooltip\" title=\"#{f.description}\"></i> "
		end
	end

	return str
end

- (DateTime) updated_at

Returns Date/Time application last updated (DM Handled)

Returns:

  • (DateTime)

    Date/Time application last updated (DM Handled)



18
# File 'models/application.rb', line 18

property :updated_at, 	DateTime

- (DateTime) updated_at=(value)

Returns Date/Time application last updated (DM Handled)

Returns:

  • (DateTime)

    Date/Time application last updated (DM Handled)



18
# File 'models/application.rb', line 18

property :updated_at, 	DateTime