Skip to content

Commit

Permalink
Add db session list and correction on ssh session list
Browse files Browse the repository at this point in the history
  • Loading branch information
elg committed Feb 24, 2020
1 parent 73fdac3 commit 35ddac7
Showing 1 changed file with 47 additions and 6 deletions.
53 changes: 47 additions & 6 deletions passhportd/app/views.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
# -*-coding:Utf-8 -*-
import psutil, re, subprocess, os
from datetime import datetime, timedelta, date
from app import app, db
from .views_mod import user, target, usergroup, targetgroup, logentry, utils
import psutil
import re
import subprocess
import os
import config
from datetime import datetime
from datetime import timedelta
from datetime import date
from app import app
from app import db
from .views_mod import user
from .views_mod import target
from .views_mod import usergroup
from .views_mod import targetgroup
from .views_mod import logentry
from .views_mod import utils
from .models_mod import logentry
from .models_mod import user
from .models_mod import target
from flask import request, stream_with_context, Response
from .models_mod import exttargetaccess
from flask import request
from flask import stream_with_context
from flask import Response
from tabulate import tabulate
import config

@app.route("/")
def imalive():
Expand Down Expand Up @@ -139,6 +153,33 @@ def currentsshconnections():
return output[:-1] + "]"


@app.route("/connection/db/current")
def currentdbconnections():
"""Return a json presenting the current database connections associated
to their PID"""
now = datetime.now()
access = exttargetaccess.Exttargetaccess.query.filter(db.and_(
exttargetaccess.Exttargetaccess.stopdate >= str(now),
exttargetaccess.Exttargetaccess.proxy_pid != 0 )).all()

if not access:
return "[]"

output = "[ "

for entry in access:
duration = now - datetime.strptime(entry.startdate,'%Y-%m-%d %H:%M:%S.%f')
output = output + \
'{"Email" : "' + \
entry.show_username() + '",' + \
'"Target" : "' + \
entry.show_targetname() + '",' + \
'"PID" : "' + str(entry.proxy_pid) + '",' + \
'"Date" : "' + hours_minutes(duration) + '"},'

return output[:-1] + "]"


@app.route("/connection/ssh/current/killbiglog")
def currecntsshconnectionskillbiglog():
"""Kill the actives sessions whith log files too big"""
Expand Down

0 comments on commit 35ddac7

Please sign in to comment.