New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deserialize JSON into MDM Objects #9394

Closed
wants to merge 57 commits into
base: master
from
Commits
Jump to file or symbol
Failed to load files and symbols.
+21 −15
Diff settings

Always

Just for now

Viewing a subset of changes. View all
@@ -1,5 +1,5 @@
module SessionDataService
def report_session(opts)
raise 'SessionDataService#report_vuln is not implemented'
raise 'SessionDataService#report_session is not implemented'
end
end
@@ -160,6 +160,21 @@ def report_session_dto(session_dto)
}
end
# Clean out any stale sessions that have been orphaned by a dead framework instance.
# @param last_seen_interval [Integer] interval, in seconds, open sessions are marked as alive
def remove_stale_sessions(last_seen_interval)
return unless active
::ActiveRecord::Base.connection_pool.with_connection {
::Mdm::Session.where(closed_at: nil).each do |db_session|
next unless db_session.last_seen.nil? or ((Time.now.utc - db_session.last_seen) > (2 * last_seen_interval))
db_session.closed_at = db_session.last_seen || Time.now.utc
db_session.close_reason = "Orphaned"
db_session.save
end
}
end
#########
protected
#########
@@ -20,7 +20,7 @@ class SessionManager < Hash
include Framework::Offspring
LAST_SEEN_INTERVAL = 60 * 2.5
LAST_SEEN_INTERVAL = 60 * 2.5
SCHEDULER_THREAD_COUNT = 5
def initialize(framework)
@@ -98,12 +98,10 @@ def initialize(framework)
end
end
#
# Skip the database cleanup code below if there is no database
#
next if not (framework.db and framework.db.active and framework.db.is_local?)
next unless framework.db && framework.db.active && framework.db.is_local?
#
# Mark all open session as alive every LAST_SEEN_INTERVAL
@@ -114,6 +112,7 @@ def initialize(framework)
# processing time for large session lists from skewing our update interval.
last_seen_timer = Time.now.utc
if framework.db.active
::ActiveRecord::Base.connection_pool.with_connection do
values.each do |s|
@@ -129,20 +128,12 @@ def initialize(framework)
end
end
#
# Clean out any stale sessions that have been orphaned by a dead
# framework instance.
#
::ActiveRecord::Base.connection_pool.with_connection do |conn|
::Mdm::Session.where(closed_at: nil).each do |db_session|
if db_session.last_seen.nil? or ((Time.now.utc - db_session.last_seen) > (2*LAST_SEEN_INTERVAL))
db_session.closed_at = db_session.last_seen || Time.now.utc
db_session.close_reason = "Orphaned"
db_session.save
end
end
end
framework.db.remove_stale_sessions(LAST_SEEN_INTERVAL)
end
#
ProTip! Use n and p to navigate between commits in a pull request.