Compare commits
5 Commits
Difrex/mas
...
jeff-99/ma
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
de2f544178 | ||
| 083144d656 | |||
| afa565104c | |||
| d5844ab267 | |||
| 48eea214fa |
2
setup.py
2
setup.py
@@ -10,7 +10,7 @@ def main():
|
|||||||
url='https://github.com/zlaxy/sshch/',
|
url='https://github.com/zlaxy/sshch/',
|
||||||
description='Ssh connection manager',
|
description='Ssh connection manager',
|
||||||
license='DWTWL 2.5',
|
license='DWTWL 2.5',
|
||||||
version='0.55',
|
version='0.7',
|
||||||
py_modules=['sshch'],
|
py_modules=['sshch'],
|
||||||
scripts=['sshch/sshch'],
|
scripts=['sshch/sshch'],
|
||||||
|
|
||||||
|
|||||||
37
sshch/sshch
37
sshch/sshch
@@ -7,14 +7,16 @@ from sys import argv
|
|||||||
from math import ceil
|
from math import ceil
|
||||||
from getpass import getpass
|
from getpass import getpass
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
from curses import textpad
|
from curses import textpad, panel
|
||||||
import ConfigParser
|
import ConfigParser
|
||||||
import subprocess
|
import subprocess
|
||||||
import base64
|
import base64
|
||||||
import curses
|
import curses
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
# https://github.com/zlaxy/sshch
|
# https://github.com/zlaxy/sshch
|
||||||
version = "0.55"
|
version = "0.7"
|
||||||
# path to conf file, default: ~/.config/sshch.conf
|
# path to conf file, default: ~/.config/sshch.conf
|
||||||
conf_file = path.expanduser("~") + '/.config/sshch.conf'
|
conf_file = path.expanduser("~") + '/.config/sshch.conf'
|
||||||
|
|
||||||
@@ -47,19 +49,24 @@ def RemoveAliases(aliases):
|
|||||||
|
|
||||||
|
|
||||||
def ConnectAlias(alias, command=False):
|
def ConnectAlias(alias, command=False):
|
||||||
print "Connecting to " + alias + "..."
|
|
||||||
exec_string = ""
|
exec_string = ""
|
||||||
if conf.has_option(alias, "password"):
|
if conf.has_option(alias, "password"):
|
||||||
password = base64.b32decode(base64.b16decode(
|
password = base64.b32decode(base64.b16decode(
|
||||||
base64.b64decode(conf.get(alias, "password"))))
|
base64.b64decode(conf.get(alias, "password"))))
|
||||||
exec_string = "sshpass -p " + password + " "
|
exec_string = 'sshpass -p "' + password + '" '
|
||||||
exec_string = exec_string + conf.get(alias, "exec_string")
|
exec_string = exec_string + conf.get(alias, "exec_string")
|
||||||
if command:
|
if command:
|
||||||
exec_string = exec_string + " " + command
|
exec_string = exec_string + " " + command
|
||||||
# Variables bellow is newer used
|
# Variables bellow is newer used
|
||||||
subprocess.Popen(exec_string, shell=True)
|
subprocess.Popen(exec_string, shell=True).communicate()[0]
|
||||||
# p.communicate()[0]
|
|
||||||
print "... " + alias + " session finished."
|
|
||||||
|
def HoldConnection(alias):
|
||||||
|
print "Connecting to " + alias + ". Press CTRL+C to cancel."
|
||||||
|
time.sleep(1)
|
||||||
|
while True:
|
||||||
|
ConnectAlias(alias)
|
||||||
|
time.sleep(5)
|
||||||
|
|
||||||
|
|
||||||
def CMDAdd(alias):
|
def CMDAdd(alias):
|
||||||
@@ -113,7 +120,9 @@ def CMDRemove(alias):
|
|||||||
def CMDConnect(aliases, command=False):
|
def CMDConnect(aliases, command=False):
|
||||||
for alias in aliases:
|
for alias in aliases:
|
||||||
if conf.has_section(alias):
|
if conf.has_section(alias):
|
||||||
|
print "Connecting to " + alias + "..."
|
||||||
ConnectAlias(alias, command)
|
ConnectAlias(alias, command)
|
||||||
|
print "... " + alias + " session finished."
|
||||||
else:
|
else:
|
||||||
print "error: '" + alias + "' alias is not exists"
|
print "error: '" + alias + "' alias is not exists"
|
||||||
|
|
||||||
@@ -132,7 +141,9 @@ def CMDFullList(option, opt, value, parser):
|
|||||||
def CursesConnect(screen, aliases, command=False):
|
def CursesConnect(screen, aliases, command=False):
|
||||||
curses.endwin()
|
curses.endwin()
|
||||||
for alias in aliases:
|
for alias in aliases:
|
||||||
|
print "Connecting to " + alias + "..."
|
||||||
ConnectAlias(alias, command)
|
ConnectAlias(alias, command)
|
||||||
|
print "... " + alias + " session finished."
|
||||||
print "Press 'enter' to continue."
|
print "Press 'enter' to continue."
|
||||||
screen.getch()
|
screen.getch()
|
||||||
|
|
||||||
@@ -176,7 +187,7 @@ def CursesPanel(screen, h, w, y, x, text,
|
|||||||
new_window.attroff(deco_colorpair)
|
new_window.attroff(deco_colorpair)
|
||||||
sub_window = new_window.subwin(h - 2, w - 2, y + 1, x + 1)
|
sub_window = new_window.subwin(h - 2, w - 2, y + 1, x + 1)
|
||||||
sub_window.insstr(0, 0, text)
|
sub_window.insstr(0, 0, text)
|
||||||
curses.panel.new_panel(new_window)
|
panel = curses.panel.new_panel(new_window)
|
||||||
curses.panel.update_panels()
|
curses.panel.update_panels()
|
||||||
screen.refresh()
|
screen.refresh()
|
||||||
if confirm == "password":
|
if confirm == "password":
|
||||||
@@ -245,6 +256,9 @@ def CMDOptions():
|
|||||||
opts.add_option('-c', '--command', action="store", type="string",
|
opts.add_option('-c', '--command', action="store", type="string",
|
||||||
dest="command", metavar="command", default=False,
|
dest="command", metavar="command", default=False,
|
||||||
help="add command for executing alias")
|
help="add command for executing alias")
|
||||||
|
opts.add_option('-k', '--keep', action="store", type="string",
|
||||||
|
dest="keep", metavar="alias", default=False,
|
||||||
|
help="hold connection with specified alias")
|
||||||
opts.add_option('-e', '--edit', action="store", type="string",
|
opts.add_option('-e', '--edit', action="store", type="string",
|
||||||
dest='edit', metavar="alias", default=False,
|
dest='edit', metavar="alias", default=False,
|
||||||
help="edit existing connection string")
|
help="edit existing connection string")
|
||||||
@@ -263,6 +277,8 @@ def CMDOptions():
|
|||||||
CMDPassword(options.password)
|
CMDPassword(options.password)
|
||||||
if options.remove:
|
if options.remove:
|
||||||
CMDRemove(options.remove)
|
CMDRemove(options.remove)
|
||||||
|
if options.keep:
|
||||||
|
HoldConnection(options.keep)
|
||||||
if alias:
|
if alias:
|
||||||
CMDConnect(alias, options.command)
|
CMDConnect(alias, options.command)
|
||||||
|
|
||||||
@@ -278,6 +294,7 @@ def CursesMain():
|
|||||||
" 'space'/'insert' - select\n",
|
" 'space'/'insert' - select\n",
|
||||||
" 'r'/'F8' - remove selected alias/aliases\n",
|
" 'r'/'F8' - remove selected alias/aliases\n",
|
||||||
" 'c'/'F3' - execute specific command with selected alias/aliases\n",
|
" 'c'/'F3' - execute specific command with selected alias/aliases\n",
|
||||||
|
" 'k'/'F7' - hold connection with selected alias\n",
|
||||||
" 'enter'/'F9' - connect to selected alias/aliases\n",
|
" 'enter'/'F9' - connect to selected alias/aliases\n",
|
||||||
" 'q'/'F10' - quit\n",
|
" 'q'/'F10' - quit\n",
|
||||||
" Run program with '--help' option to view command line help.\n",
|
" Run program with '--help' option to view command line help.\n",
|
||||||
@@ -428,6 +445,10 @@ def CursesMain():
|
|||||||
command_string = command_textpad.edit(CursesTextpadConfirm)
|
command_string = command_textpad.edit(CursesTextpadConfirm)
|
||||||
CursesConnect(screen, selected,
|
CursesConnect(screen, selected,
|
||||||
command_string.replace("\n", "").rstrip())
|
command_string.replace("\n", "").rstrip())
|
||||||
|
if (key_pressed == ord('k') or key_pressed == ord('K') or
|
||||||
|
key_pressed == (curses.KEY_F7)) and row_num != 0:
|
||||||
|
curses.endwin()
|
||||||
|
HoldConnection(strings[position - 1])
|
||||||
if (key_pressed == ord("\n") or key_pressed == (
|
if (key_pressed == ord("\n") or key_pressed == (
|
||||||
curses.KEY_F9)) and row_num != 0:
|
curses.KEY_F9)) and row_num != 0:
|
||||||
selected = []
|
selected = []
|
||||||
|
|||||||
11
sshch_bash_completion.sh
Normal file
11
sshch_bash_completion.sh
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
_sshch_complete()
|
||||||
|
{
|
||||||
|
local cur_word alias_list
|
||||||
|
cur_word="${COMP_WORDS[COMP_CWORD]}"
|
||||||
|
alias_list=`sshch -l | sed 's/,//g'`
|
||||||
|
COMPREPLY=($(compgen -W "$alias_list" -- $cur_word))
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
complete -F _sshch_complete sshch
|
||||||
|
|
||||||
Reference in New Issue
Block a user