bugfix ident

This commit is contained in:
nojhan 2010-09-08 21:15:39 +00:00
commit 6bb4f4d0e5
3 changed files with 45 additions and 64 deletions

View file

@ -2,5 +2,5 @@ N:Johann Dréo
P:nojhan P:nojhan
E:nojhan@gmail.com E:nojhan@gmail.com
D:2009-06-23 D:2009-06-23
C:Initial code, maintener C:Initial code, lead developper

View file

@ -1,3 +1,7 @@
current:
* added a via_host field (show on which host the tunnel is build)
* don't try to show connections if the user is not root
0.2: 0.2:
* update from the deprecated popen3 functions to the subprocess module (need python >= 2.4) * update from the deprecated popen3 functions to the subprocess module (need python >= 2.4)
* html help page * html help page

View file

@ -4,18 +4,18 @@
# Ereshkigal is an AutoSSH tunnel monitor # Ereshkigal is an AutoSSH tunnel monitor
# It gives a curses user interface to monitor existing SSH tunnel that are managed with autossh. # It gives a curses user interface to monitor existing SSH tunnel that are managed with autossh.
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or # the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version. # (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
# Author : Johann "nojhan" Dréo <nojhan@gmail.com> # Author : Johann "nojhan" Dréo <nojhan@gmail.com>
# #
@ -31,18 +31,9 @@ import subprocess
from operator import itemgetter from operator import itemgetter
class SSHTunnel(dict): class SSHTunnel(dict):
"""A dictionary that stores an SSH connection related to a tunnel""" """A dictionary that stores an SSH connection related to a tunnel"""
def __init__(self, def __init__(self, local_address = '1.1.1.1', local_port = 0, foreign_address = '1.1.1.1', foreign_port = 0, target_host = "Unknown", status = 'UNKNOWN', ssh_pid = 0, autossh_pid = 0 ):
local_address = '1.1.1.1',
local_port = 0,
foreign_address = '1.1.1.1',
foreign_port = 0,
target_host = "Unknown",
status = 'UNKNOWN',
ssh_pid = 0,
autossh_pid = 0
):
# informations available with netstat # informations available with netstat
self['local_address'] = local_address self['local_address'] = local_address
@ -69,7 +60,7 @@ class SSHTunnel(dict):
class AutoSSHInstance(dict): class AutoSSHInstance(dict):
"""A dictionary that stores an autossh process""" """A dictionary that stores an autossh process"""
def __init__(self, pid = 0, local_port = 0, via_host="Unknown", target_host = "Unknown",foreign_port = 0): def __init__(self, pid = 0, local_port = 0, via_host="Unknown", target_host = "Unknown",foreign_port = 0):
@ -98,7 +89,7 @@ class AutoSSHInstance(dict):
class AutoSSHTunnelMonitor(list): class AutoSSHTunnelMonitor(list):
"""List of existing autossh processes and ssh connections""" """List of existing autossh processes and ssh connections"""
def __init__(self): def __init__(self):
"""Warning: the initialization does not gather tunnels informations, use update() to do so""" """Warning: the initialization does not gather tunnels informations, use update() to do so"""
@ -150,19 +141,19 @@ class AutoSSHTunnelMonitor(list):
# use the operator module # use the operator module
self[:] = sorted( self, key=itemgetter( key ) ) self[:] = sorted( self, key=itemgetter( key ) )
def get_autossh_instances(self): def get_autossh_instances(self):
"""Gather and parse autossh processes""" """Gather and parse autossh processes"""
def get_autossh_instances(self): def get_autossh_instances(self):
"""Gather and parse autossh processes""" """Gather and parse autossh processes"""
# call the command # call the command
#status = os.popen3( self.ps_cmd ) #status = os.popen3( self.ps_cmd )
p = subprocess.Popen( self.ps_cmd, shell=True, p = subprocess.Popen( self.ps_cmd, shell=True,
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True) stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True)
status = (p.stdin, p.stdout, p.stderr) status = (p.stdin, p.stdout, p.stderr)
# list of processes with the "autossh" string # list of processes with the "autossh" string
@ -201,13 +192,13 @@ class AutoSSHTunnelMonitor(list):
def get_connections(self): def get_connections(self):
"""Gather and parse ssh connections related to a tunnel""" """Gather and parse ssh connections related to a tunnel"""
#status = os.popen3( self.network_cmd ) #status = os.popen3( self.network_cmd )
p = subprocess.Popen( self.network_cmd, shell=True, p = subprocess.Popen( self.network_cmd, shell=True,
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True) stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True)
status = (p.stdin, p.stdout, p.stderr) status = (p.stdin, p.stdout, p.stderr)
status_list = status[1].readlines() status_list = status[1].readlines()
list = [i.split() for i in status_list if 'ssh' in i] list = [i.split() for i in status_list if 'ssh' in i]
@ -274,23 +265,7 @@ class AutoSSHTunnelMonitor(list):
# add to the list of tunnels of the AutoSSHInstance instance # add to the list of tunnels of the AutoSSHInstance instance
i['tunnels'] += [t] i['tunnels'] += [t]
return autosshs return tunnels
# instanciation
tunnels += [ SSHTunnel( local_addr, local_port, foreign_addr, foreign_port, autohost, status, sshpid, ppid ) ]
return tunnels
def bind_tunnels(self, autosshs, tunnels):
"""Bind autossh process to the related ssh connections, according to the pid"""
for t in tunnels:
for i in autosshs:
if i['pid'] == t['autossh_pid']:
# add to the list of tunnels of the AutoSSHInstance instance
i['tunnels'] += [t]
return autosshs
################################################################################################# #################################################################################################
@ -302,7 +277,7 @@ import time
import signal import signal
class monitorCurses: class monitorCurses:
"""Textual user interface to display up-to-date informations about current tunnels""" """Textual user interface to display up-to-date informations about current tunnels"""
def __init__(self, scr): def __init__(self, scr):
# curses screen # curses screen
@ -359,6 +334,8 @@ class monitorCurses:
if kc != -1: # if keypress if kc != -1: # if keypress
pass pass
ch = chr(0)
if 0 < kc < 256: # if ascii key if 0 < kc < 256: # if ascii key
# ascii character from the keycode # ascii character from the keycode
ch = chr(kc) ch = chr(kc)
@ -516,8 +493,8 @@ class monitorCurses:
self.scr.clrtoeol() self.scr.clrtoeol()
def add_autossh_info( self, key, line ): def add_autossh_info( self, key, line ):
"""Add an information of an autossh process, in the configured color""" """Add an information of an autossh process, in the configured color"""
def add_autossh_info( self, key, line ): def add_autossh_info( self, key, line ):
"""Add an information of an autossh process, in the configured color""" """Add an information of an autossh process, in the configured color"""
@ -538,14 +515,14 @@ class monitorCurses:
self.scr.addstr( '\t', curses.color_pair(colors[key]) ) self.scr.addstr( '\t', curses.color_pair(colors[key]) )
if __name__ == "__main__": if __name__ == "__main__":
import sys import sys
from optparse import OptionParser from optparse import OptionParser
usage = """%prog [options] usage = """%prog [options]
A user interface to monitor existing SSH tunnel that are managed with autossh. A user interface to monitor existing SSH tunnel that are managed with autossh.
Called without options, ereshkigal displays a list of tunnels on the standard output. Called without options, ereshkigal displays a list of tunnels on the standard output.
Note: Users other than root will not see tunnels connections""" Note: Users other than root will not see tunnels connections"""
parser = OptionParser(usage=usage) parser = OptionParser(usage=usage)
parser.add_option("-c", "--curses", action="store_true", dest="curses", default=False, parser.add_option("-c", "--curses", action="store_true", dest="curses", default=False,
help="start the user interface in text mode") help="start the user interface in text mode")
@ -554,7 +531,7 @@ Note: Users other than root will not see tunnels connections"""
parser.add_option("-a", "--autossh", action="store_true", dest="autossh", default=False, parser.add_option("-a", "--autossh", action="store_true", dest="autossh", default=False,
help="display only the list of autossh processes") help="display only the list of autossh processes")
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
# unfortunately, options class has no __len__ method in python 2.4.3 (bug?) # unfortunately, options class has no __len__ method in python 2.4.3 (bug?)
#if len(options) > 1: #if len(options) > 1: