Skip to content

Commit c295801

Browse files
committed
Setup docs
1 parent 040be1a commit c295801

File tree

6 files changed

+57
-68
lines changed

6 files changed

+57
-68
lines changed

docs/Makefile

Lines changed: 0 additions & 20 deletions
This file was deleted.

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
# Add any Sphinx extension module names here, as strings. They can be
2828
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
2929
# ones.
30-
extensions = ['recommonmark']
30+
extensions = ['recommonmark', 'sphinx_rtd_theme']
3131

3232
# Add any paths that contain templates here, relative to this directory.
3333
templates_path = ['_templates']
@@ -43,7 +43,7 @@
4343
# The theme to use for HTML and HTML Help pages. See the documentation for
4444
# a list of builtin themes.
4545
#
46-
html_theme = 'master'
46+
html_theme = 'sphinx_rtd_theme'
4747

4848
# Add any paths that contain custom static files (such as style sheets) here,
4949
# relative to this directory. They are copied after the builtin static files,

docs/index.rst

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,3 @@
1212

1313
injectorshell
1414
scriptedshell
15-
16-
17-
18-
Indices and tables
19-
==================
20-
21-
* :ref:`genindex`
22-
* :ref:`modindex`
23-
* :ref:`search`

docs/make.bat

Lines changed: 0 additions & 35 deletions
This file was deleted.

plugins/__entrypoints__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
entry_points = {
22
'SSHBaseForwarder': [
3-
'scriptedshell = plugins.ssh:SSHScriptedForwarder',
3+
'scriptedshell = plugins.ssh.scriptedshell:SSHScriptedForwarder',
44
],
55
'SCPBaseForwarder': [
66

@@ -20,4 +20,4 @@
2020
'Authenticator': [
2121

2222
]
23-
}
23+
}

plugins/ssh/scriptedshell.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import logging
2+
import os
3+
4+
from ssh_proxy_server.forwarders.ssh import SSHForwarder
5+
6+
7+
class SSHScriptedForwarder(SSHForwarder):
8+
9+
@classmethod
10+
def parser_arguments(cls):
11+
cls.PARSER.add_argument(
12+
'--ssh-script',
13+
dest='ssh_script',
14+
help='script to execute on ssh connection',
15+
required=True
16+
)
17+
cls.PARSER.add_argument(
18+
'--ssh-out-dir',
19+
dest='ssh_out_dir',
20+
help='script output directory',
21+
default='.'
22+
)
23+
24+
def __init__(self, session):
25+
super(SSHScriptedForwarder, self).__init__(session)
26+
self.executing = False
27+
self.script = open(os.path.expanduser(self.args.ssh_script), "r")
28+
self.output = open(os.path.expanduser(os.path.join(self.args.ssh_out_dir, str(self.session))), "w+")
29+
30+
def forward_stdin(self):
31+
if self.executing:
32+
line = self.script.readline()
33+
self.server_channel.sendall(line)
34+
return
35+
if not self.executing and not self.script.closed and self.session.ssh_channel.recv_ready():
36+
self.executing = True
37+
super(SSHScriptedForwarder, self).forward_stdin()
38+
39+
def forward_stdout(self):
40+
if not self.server_channel.recv_ready() and self.executing:
41+
self.executing = False
42+
self.script.close()
43+
self.output.close()
44+
super(SSHScriptedForwarder, self).forward_stdout()
45+
46+
def stdout(self, text):
47+
if self.executing:
48+
self.output.write(text.decode('utf-8'))
49+
return ""
50+
return text
51+
52+
def close_session(self, channel):
53+
super().close_session(channel)

0 commit comments

Comments
 (0)