Skip to content

lock destination parameters #223

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,4 @@ target/

# known_hosts file
known_hosts
.vscode/launch.json
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ A simple web application to be used as an ssh client to connect to your ssh serv
# start a http server with specified listen address and listen port
wssh --address='2.2.2.2' --port=8000

# lock destination address and port
wssh --dstaddress='127.0.0.1' --dstport=22

# start a https server, certfile and keyfile must be passed
wssh --certfile='/path/to/cert.crt' --keyfile='/path/to/cert.key'

Expand Down
13 changes: 8 additions & 5 deletions webssh/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,7 @@ def get_pkey_obj(self):
logging.error(str(self.last_exception))
msg = 'Invalid key'
if self.password:
msg += ' or wrong passphrase "{}" for decrypting it.'.format(
self.password)
msg += ' or wrong passphrase for decrypting it.'
raise InvalidValueError(msg)


Expand Down Expand Up @@ -362,13 +361,17 @@ def get_privatekey(self):
return value, filename

def get_hostname(self):
value = self.get_value('hostname')
value = self.settings.get('dstaddress')
if not value:
value = self.get_value('hostname')
if not (is_valid_hostname(value) or is_valid_ip_address(value)):
raise InvalidValueError('Invalid hostname: {}'.format(value))
return value

def get_port(self):
value = self.get_argument('port', u'')
value = self.settings.get('dstport',u'')
if not value:
value = self.get_argument('port', u'')
if not value:
return DEFAULT_PORT

Expand Down Expand Up @@ -482,7 +485,7 @@ def head(self):
pass

def get(self):
self.render('index.html', debug=self.debug, font=self.font)
self.render('index.html', debug=self.debug, font=self.font, fixhost=self.settings.get('dstaddress'), fixport=self.settings.get('dstport'))

@tornado.gen.coroutine
def post(self):
Expand Down
10 changes: 6 additions & 4 deletions webssh/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def print_version(flag):
print(__version__)
sys.exit(0)


define('address', default='', help='Listen address')
define('port', type=int, default=8888, help='Listen port')
define('ssladdress', default='', help='SSL listen address')
Expand Down Expand Up @@ -53,7 +52,8 @@ def print_version(flag):
Example: --encoding='utf-8' to solve the problem with some switches&routers''')
define('version', type=bool, help='Show version information',
callback=print_version)

define('dstaddress', default='', help='Fix destination address')
define('dstport', default='', help='Fix destination port')

base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
font_dirs = ['webssh', 'static', 'css', 'fonts']
Expand All @@ -79,13 +79,15 @@ def get_app_settings(options):
static_path=os.path.join(base_dir, 'webssh', 'static'),
websocket_ping_interval=options.wpintvl,
debug=options.debug,
xsrf_cookies=options.xsrf,
xsrf_cookies=options.xsrf,
font=Font(
get_font_filename(options.font,
os.path.join(base_dir, *font_dirs)),
font_dirs[1:]
),
origin_policy=get_origin_setting(options)
origin_policy=get_origin_setting(options),
dstaddress=options.dstaddress,
dstport=options.dstport
)
return settings

Expand Down
8 changes: 4 additions & 4 deletions webssh/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@
<div class="container form-container" style="display: none">
<form id="connect" action="" method="post" enctype="multipart/form-data"{% if debug %} novalidate{% end %}>
<div class="row">
<div class="col">
<div class="col" id="hostcol"{% if fixhost %} hidden{% end %}>
<label for="Hostname">Hostname</label>
<input class="form-control" type="text" id="hostname" name="hostname" value="" required>
<input class="form-control" type="text" id="hostname" name="hostname" value="{{fixhost}}" required>
</div>
<div class="col">
<div class="col" id="portcol"{% if fixport %} hidden{% end %}>
<label for="Port">Port</label>
<input class="form-control" type="number" id="port" name="port" placeholder="22" value="" min=1 max=65535>
<input class="form-control" type="number" id="port" name="port" placeholder="22" value="{{fixport}}" min=1 max=65535>
</div>
</div>
<div class="row">
Expand Down