Skip to content

Commit

Permalink
Handle same PID during the same day
Browse files Browse the repository at this point in the history
  • Loading branch information
elg committed Jul 18, 2019
1 parent 7ee6d03 commit 3a19dfa
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions passhportd/app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ def checkandterminatesshsession():
isodate = datetime.now().isoformat().replace(":",""). \
replace("-","").split('.')[0]
lentries = logentry.Logentry.query.filter(
logentry.Logentry.endsessiondate == None).all()

logentry.Logentry.endsessiondate == None).all()
if not lentries:
return "No active connection."

Expand Down Expand Up @@ -236,14 +236,14 @@ def endsshsession(pid):
# modify the associated Logentry to signal the end date
isodate = datetime.now().isoformat().replace(":",""). \
replace("-","").split('.')[0]
lentry = logentry.Logentry.query.filter(
logentry.Logentry.pid == int(pid)).first()
# taking the last connection with this PID (the most recent)
lentry = logentry.Logentry.query.filter(db.and_(
logentry.Logentry.pid == int(pid),
logentry.Logentry.endsessiondate == None)).first()

if not lentry:
return "Error: no logentry with this PID"

if lentry.endsessiondate:
return "Already ended"
lentry.setenddate(isodate)

try:
Expand All @@ -252,7 +252,8 @@ def endsshsession(pid):
return utils.response('ERROR: "' + name + '" -> ' + e.message, 409)

#At last change the root password if needed
lentry.target[0].changepass(isodate)
if lentry.target:
lentry.target[0].changepass(isodate)

return "Done"

Expand Down

0 comments on commit 3a19dfa

Please sign in to comment.