Commit 0c9db2ab by Sheng

Set default port 22 on server side

parent 66891cb7
...@@ -92,10 +92,6 @@ class TestAppBasic(AsyncHTTPTestCase): ...@@ -92,10 +92,6 @@ class TestAppBasic(AsyncHTTPTestCase):
response = self.sync_post(body) response = self.sync_post(body)
self.assert_response(b'Missing argument hostname', response) 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' body = 'hostname=127.0.0.1&port=7000&password&_xsrf=yummy'
response = self.sync_post(body) response = self.sync_post(body)
self.assert_response(b'Missing argument username', response) self.assert_response(b'Missing argument username', response)
...@@ -104,10 +100,6 @@ class TestAppBasic(AsyncHTTPTestCase): ...@@ -104,10 +100,6 @@ class TestAppBasic(AsyncHTTPTestCase):
response = self.sync_post(body) response = self.sync_post(body)
self.assert_response(b'Missing value hostname', response) 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' body = 'hostname=127.0.0.1&port=7000&username=&password&_xsrf=yummy'
response = self.sync_post(body) response = self.sync_post(body)
self.assert_response(b'Missing value username', response) self.assert_response(b'Missing value username', response)
......
...@@ -30,6 +30,7 @@ except ImportError: ...@@ -30,6 +30,7 @@ except ImportError:
DELAY = 3 DELAY = 3
KEY_MAX_SIZE = 16384 KEY_MAX_SIZE = 16384
DEFAULT_PORT = 22
class InvalidValueError(Exception): class InvalidValueError(Exception):
...@@ -154,11 +155,14 @@ class IndexHandler(MixinHandler, tornado.web.RequestHandler): ...@@ -154,11 +155,14 @@ class IndexHandler(MixinHandler, tornado.web.RequestHandler):
return value return value
def get_port(self): 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) port = to_int(value)
if port and is_valid_port(port): if port is None or not is_valid_port(port):
return port
raise InvalidValueError('Invalid port: {}'.format(value)) raise InvalidValueError('Invalid port: {}'.format(value))
return port
def lookup_hostname(self, hostname, port): def lookup_hostname(self, hostname, port):
key = hostname if port == 22 else '[{}]:{}'.format(hostname, port) key = hostname if port == 22 else '[{}]:{}'.format(hostname, port)
......
...@@ -387,11 +387,7 @@ jQuery(function($){ ...@@ -387,11 +387,7 @@ jQuery(function($){
attr = attrs[i]; attr = attrs[i];
val = data.get(attr); val = data.get(attr);
if (typeof val === 'string') { if (typeof val === 'string') {
val = val.trim(); data.set(attr, val.trim());
if (attr === 'port' && val === '') {
val = 22;
}
data.set(attr, val);
} }
} }
} }
...@@ -410,7 +406,7 @@ jQuery(function($){ ...@@ -410,7 +406,7 @@ jQuery(function($){
if (!hostname) { if (!hostname) {
msg = 'Need value hostname'; msg = 'Need value hostname';
} else if (!port) { } else if (!port) {
msg = 'Need value port'; msg = '';
} else if (!username) { } else if (!username) {
msg = 'Need value username'; msg = 'Need value username';
} else if (!hostname_tester.test(hostname)) { } 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