-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from supertylerc/supertylerc/style-changes
PEP8 Clean Up
- Loading branch information
Showing
5 changed files
with
151 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,42 +4,42 @@ | |
# | ||
|
||
# Meta | ||
__license__ = "AGPLv3" | ||
__author__ = 'Ahmed Nazmy <[email protected]>' | ||
|
||
import getpass | ||
import logging | ||
import paramiko | ||
import os | ||
import select | ||
import signal | ||
import socket | ||
import tty | ||
import sys | ||
import termios | ||
import signal | ||
import select | ||
import os | ||
import tty | ||
|
||
import paramiko | ||
|
||
__license__ = "AGPLv3" | ||
__author__ = 'Ahmed Nazmy <[email protected]>' | ||
|
||
TIME_OUT = 10 | ||
|
||
|
||
class Client(object): | ||
def __init__(self, session): | ||
self._session = session | ||
|
||
|
||
|
||
class SSHClient(Client): | ||
def __init__(self, session): | ||
super(SSHClient, self).__init__(session) | ||
self._socket = None | ||
logging.debug("Client: Client Created") | ||
|
||
def connect(self, ip, port, size): | ||
self._size = size | ||
self._socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | ||
self._socket.settimeout(TIME_OUT) | ||
self._socket.connect((ip, port)) | ||
logging.debug("SSHClient: Connected to {0}:{1}".format(ip,port)) | ||
|
||
|
||
logging.debug("SSHClient: Connected to {0}:{1}".format(ip, port)) | ||
|
||
def get_transport(self): | ||
transport = paramiko.Transport(self._socket) | ||
transport.set_keepalive(10) | ||
|
@@ -61,7 +61,7 @@ def start_session(self, user, auth_secret): | |
transport.auth_password(user, getpass.getpass()) | ||
self._start_session(transport) | ||
except EOFError as exc: | ||
logging.error('Received EOFError. Assuming bad SSH implementation.') | ||
logging.error('EOFError. Assuming bad SSH implementation.') | ||
logging.error('Original Erorr: %s', exc) | ||
self._handle_exception(transport) | ||
except Exception as e: | ||
|
@@ -75,7 +75,6 @@ def _handle_exception(self, transport): | |
transport.close() | ||
self._socket.close() | ||
|
||
|
||
def _start_session(self, transport): | ||
chan = transport.open_session() | ||
cols, rows = self._size | ||
|
@@ -87,7 +86,6 @@ def _start_session(self, transport): | |
transport.close() | ||
self._socket.close() | ||
|
||
|
||
def interactive_shell(self, chan): | ||
# Handle session IO | ||
sys.stdout.flush() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,59 +2,58 @@ | |
# | ||
# Copyright 2016 Ahmed Nazmy | ||
# | ||
|
||
# Meta | ||
__license__ = "AGPLv3" | ||
__author__ = 'Ahmed Nazmy <[email protected]>' | ||
|
||
import getpass | ||
import logging | ||
import signal | ||
import os | ||
import signal | ||
|
||
from SSHClient import SSHClient | ||
|
||
__license__ = "AGPLv3" | ||
__author__ = 'Ahmed Nazmy <[email protected]>' | ||
|
||
|
||
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 | ||
|
||
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 | ||
# 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 | ||
# 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 | ||
""" Wrapper around SSHClient instantiating | ||
a new SSHClient instance everytime | ||
""" | ||
def __init__(self, aker_core, host,uuid): | ||
super(SSHSession, self).__init__(aker_core, host,uuid) | ||
|
||
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): | ||
try: | ||
auth_secret = self.aker.user.get_priv_key() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,16 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright 2016 Ahmed Nazmy | ||
# Copyright 2016 Ahmed Nazmy | ||
# | ||
|
||
# Meta | ||
__license__ = "AGPLv3" | ||
__author__ = 'Ahmed Nazmy <[email protected]>' | ||
|
||
|
||
|
||
from Queue import Queue | ||
import logging | ||
import os | ||
from Queue import Queue | ||
import stat | ||
import threading | ||
import os | ||
import sys | ||
import codecs | ||
|
||
__license__ = "AGPLv3" | ||
__author__ = 'Ahmed Nazmy <[email protected]>' | ||
|
||
|
||
class Sniffer(object): | ||
|
@@ -57,6 +52,7 @@ def restore(self): | |
self._sniffer.join() | ||
self.log_filename = None | ||
|
||
|
||
class SessionSniffer(threading.Thread): | ||
def __init__(self, keys_queue): | ||
threading.Thread.__init__(self) | ||
|
@@ -71,7 +67,12 @@ def set_log_filename(self, log_filename): | |
def run(self): | ||
if self._log_filename: | ||
self._log_file = open(self._log_filename, "wb") | ||
os.chmod(self._log_file.name, stat.S_IREAD | stat.S_IWRITE | stat.S_IWRITE | stat.S_IRGRP | stat.S_IROTH) | ||
os.chmod(self._log_file.name, | ||
stat.S_IREAD | | ||
stat.S_IWRITE | | ||
stat.S_IWRITE | | ||
stat.S_IRGRP | | ||
stat.S_IROTH) | ||
while True: | ||
if not self._session_stop: | ||
c = self._key_queue.get() | ||
|
Oops, something went wrong.