Commit 0c9db2ab by Sheng

Set default port 22 on server side

parent 66891cb7
......@@ -92,10 +92,6 @@ class TestAppBasic(AsyncHTTPTestCase):
response = self.sync_post(body)
self.assert_response(b'Missing argument hostname', response)
body = 'hostname=127.0.0.1&username=admin&password&_xsrf=yummy'
response = self.sync_post(body)
self.assert_response(b'Missing argument port', response)
body = 'hostname=127.0.0.1&port=7000&password&_xsrf=yummy'
response = self.sync_post(body)
self.assert_response(b'Missing argument username', response)
......@@ -104,10 +100,6 @@ class TestAppBasic(AsyncHTTPTestCase):
response = self.sync_post(body)
self.assert_response(b'Missing value hostname', response)
body = 'hostname=127.0.0.1&port=&username=&password&_xsrf=yummy'
response = self.sync_post(body)
self.assert_response(b'Missing value port', response)
body = 'hostname=127.0.0.1&port=7000&username=&password&_xsrf=yummy'
response = self.sync_post(body)
self.assert_response(b'Missing value username', response)
......
......@@ -30,6 +30,7 @@ except ImportError:
DELAY = 3
KEY_MAX_SIZE = 16384
DEFAULT_PORT = 22
class InvalidValueError(Exception):
......@@ -154,11 +155,14 @@ class IndexHandler(MixinHandler, tornado.web.RequestHandler):
return value
def get_port(self):
value = self.get_value('port')
value = self.get_argument('port', u'')
if not value:
return DEFAULT_PORT
port = to_int(value)
if port and is_valid_port(port):
return port
if port is None or not is_valid_port(port):
raise InvalidValueError('Invalid port: {}'.format(value))
return port
def lookup_hostname(self, hostname, port):
key = hostname if port == 22 else '[{}]:{}'.format(hostname, port)
......
......@@ -387,11 +387,7 @@ jQuery(function($){
attr = attrs[i];
val = data.get(attr);
if (typeof val === 'string') {
val = val.trim();
if (attr === 'port' && val === '') {
val = 22;
}
data.set(attr, val);
data.set(attr, val.trim());
}
}
}
......@@ -410,7 +406,7 @@ jQuery(function($){
if (!hostname) {
msg = 'Need value hostname';
} else if (!port) {
msg = 'Need value port';
msg = '';
} else if (!username) {
msg = 'Need value username';
} else if (!hostname_tester.test(hostname)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment