forked from aker-gateway/Aker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
session.py
60 lines (46 loc) · 1.42 KB
/
session.py
1
2
3
4
5
6
7
8
9
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
# -*- coding: utf-8 -*-
#
# Copyright 2016 Ahmed Nazmy
#
# Meta
__license__ = "AGPLv3"
__author__ = 'Ahmed Nazmy <[email protected]>'
import logging
import signal
import os
from SSHClient import SSHClient
class Session(object):
""" Base class for sessions
Different type of sessions to be
added later
"""
def __init__(self,aker_core,host,uuid):
self.aker= aker_core
self.host = host
self.host_user = self.aker.user.ssh_hosts[host]['username']
self.host_port = int(self.aker.user.ssh_hosts[host]['port'])
self.uuid = uuid
logging.debug("Session: Base Session created")
#TODO : Add UUID shit
def connect(self, size):
self._client.connect(self.host, self.host_port, size)
def start_session(self):
raise NotImplementedError
def close_session(self):
self.aker.session_end_callback(self)
def kill_session(self, signum, stack):
#TODO : Change behavoir to show screen again
logging.debug("Session: Session Killed")
self.close_session()
os.kill(os.getpid(), signal.SIGKILL)
class SSHSession(Session):
""" Wrapper around SSHClient instantiating
a new SSHClient instance everytime
"""
def __init__(self, aker_core, host,uuid):
super(SSHSession, self).__init__(aker_core, host,uuid)
self._client = SSHClient(self)
logging.debug("Session: SSHSession created")
def start_session(self):
priv_key = self.aker.user.get_priv_key()
self._client.start_session(self.host_user,priv_key)