Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
webssh
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
郑天保
webssh
Commits
4710d8c0
Commit
4710d8c0
authored
Aug 24, 2018
by
Sheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added connect_with_options function
parent
ee7fd101
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
85 additions
and
21 deletions
+85
-21
test_app.py
tests/test_app.py
+2
-1
handler.py
webssh/handler.py
+15
-13
main.js
webssh/static/js/main.js
+68
-7
No files found.
tests/test_app.py
View file @
4710d8c0
...
...
@@ -213,12 +213,13 @@ class TestApp(AsyncHTTPTestCase):
headers
=
{
'Content-Type'
:
content_type
,
'content-length'
:
str
(
len
(
body
))
}
response
=
yield
client
.
fetch
(
url
,
method
=
'POST'
,
headers
=
headers
,
body
=
body
)
data
=
json
.
loads
(
to_str
(
response
.
body
))
self
.
assertIsNone
(
data
[
'id'
])
self
.
assertIsNone
(
data
[
'encoding'
])
self
.
assert
True
(
data
[
'status'
]
.
startswith
(
'Invalid private key'
)
)
self
.
assert
In
(
'Bad Request (Invalid unicode'
,
data
[
'status'
]
)
@tornado.testing.gen_test
def
test_app_post_form_with_large_body_size
(
self
):
...
...
webssh/handler.py
View file @
4710d8c0
...
...
@@ -66,21 +66,23 @@ class IndexHandler(MixinHandler, tornado.web.RequestHandler):
self
.
loop
=
loop
self
.
policy
=
policy
self
.
host_keys_settings
=
host_keys_settings
self
.
filename
=
None
def
get_privatekey
(
self
):
lst
=
self
.
request
.
files
.
get
(
'privatekey'
)
if
not
lst
:
# no privatekey provided
return
self
.
filename
=
lst
[
0
][
'filename'
]
data
=
lst
[
0
][
'body'
]
if
len
(
data
)
<
KEY_MAX_SIZE
:
lst
=
self
.
request
.
files
.
get
(
'privatekey'
)
# multipart form
if
not
lst
:
try
:
return
to_str
(
data
)
except
(
UnicodeDecodeError
,
ValueError
,
SyntaxError
)
:
return
self
.
get_argument
(
'privatekey'
)
# urlencoded form
except
tornado
.
web
.
MissingArgumentError
:
pass
raise
ValueError
(
'Invalid private key: {}'
.
format
(
self
.
filename
))
else
:
self
.
filename
=
lst
[
0
][
'filename'
]
data
=
lst
[
0
][
'body'
]
if
len
(
data
)
>
KEY_MAX_SIZE
:
raise
ValueError
(
'Invalid private key: {}'
.
format
(
self
.
filename
)
)
return
self
.
decode_argument
(
data
,
name
=
self
.
filename
)
@classmethod
def
get_specific_pkey
(
cls
,
pkeycls
,
privatekey
,
password
):
...
...
@@ -119,7 +121,7 @@ class IndexHandler(MixinHandler, tornado.web.RequestHandler):
value
=
self
.
get_value
(
'hostname'
)
if
not
(
is_valid_hostname
(
value
)
|
is_valid_ipv4_address
(
value
)
|
is_valid_ipv6_address
(
value
)):
raise
ValueError
(
'Invalid hostname: {}
.
'
.
format
(
value
))
raise
ValueError
(
'Invalid hostname: {}'
.
format
(
value
))
return
value
def
get_port
(
self
):
...
...
@@ -132,7 +134,7 @@ class IndexHandler(MixinHandler, tornado.web.RequestHandler):
if
is_valid_port
(
port
):
return
port
raise
ValueError
(
'Invalid port: {}
.
'
.
format
(
value
))
raise
ValueError
(
'Invalid port: {}'
.
format
(
value
))
def
get_value
(
self
,
name
):
value
=
self
.
get_argument
(
name
)
...
...
webssh/static/js/main.js
View file @
4710d8c0
...
...
@@ -105,7 +105,7 @@ jQuery(function($){
}
function
callback
(
resp
)
{
function
ajax_complete_
callback
(
resp
)
{
btn
.
prop
(
'disabled'
,
false
);
if
(
resp
.
status
!==
200
)
{
...
...
@@ -116,6 +116,7 @@ jQuery(function($){
var
msg
=
resp
.
responseJSON
;
if
(
msg
.
status
)
{
console
.
log
(
msg
);
status
.
text
(
msg
.
status
);
return
;
}
...
...
@@ -275,7 +276,7 @@ jQuery(function($){
}
function
connect
()
{
function
connect
_without_options
()
{
if
(
connected
)
{
console
.
log
(
'This client was already connected.'
);
return
;
...
...
@@ -298,7 +299,7 @@ jQuery(function($){
url
:
url
,
type
:
'post'
,
data
:
data
,
complete
:
callback
,
complete
:
ajax_complete_
callback
,
cache
:
false
,
contentType
:
false
,
processData
:
false
...
...
@@ -323,11 +324,11 @@ jQuery(function($){
var
pk
=
data
.
get
(
'privatekey'
);
if
(
pk
)
{
if
(
pk
.
size
>
key_max_size
)
{
status
.
text
(
'Invalid private key: '
+
pk
.
name
);
console
.
log
(
'Invalid private key: '
+
pk
.
name
);
}
else
{
read_file_as_text
(
pk
,
function
(
text
)
{
if
(
text
===
undefined
)
{
status
.
text
(
'Invalid private key: '
+
pk
.
name
);
console
.
log
(
'Invalid private key: '
+
pk
.
name
);
}
else
{
ajax_post
();
}
...
...
@@ -338,11 +339,71 @@ jQuery(function($){
}
}
wssh
.
connect
=
connect
;
function
connect_with_options
(
opts
)
{
if
(
connected
)
{
console
.
log
(
'This client was already connected.'
);
return
;
}
var
form
=
document
.
querySelector
(
form_id
),
xsrf
=
form
.
querySelector
(
'input[name="_xsrf"]'
).
value
,
url
=
opts
.
url
||
form
.
action
,
hostname
=
opts
.
hostname
||
''
,
port
=
opts
.
port
||
''
,
username
=
opts
.
username
||
''
,
password
=
opts
.
password
||
''
,
privatekey
=
opts
.
privatekey
||
''
,
data
=
{
'_xsrf'
:
xsrf
,
'username'
:
username
,
'hostname'
:
hostname
,
'port'
:
port
,
'password'
:
password
,
'privatekey'
:
privatekey
};
if
(
!
hostname
||
!
port
||
!
username
)
{
console
.
log
(
'Fields hostname, port and username are all required.'
);
return
;
}
if
(
!
hostname_tester
.
test
(
hostname
))
{
console
.
log
(
'Invalid hostname: '
+
hostname
);
return
;
}
if
(
port
<=
0
||
port
>
63335
)
{
console
.
log
(
'Invalid port: '
+
port
);
return
;
}
if
(
privatekey
&&
privatekey
.
length
>
key_max_size
)
{
console
.
log
(
'Invalid private key: '
+
privatekey
);
return
;
}
$
.
ajax
({
url
:
url
,
type
:
'post'
,
data
:
data
,
complete
:
ajax_complete_callback
});
}
wssh
.
connect
=
function
(
opts
)
{
if
(
opts
===
undefined
)
{
connect_without_options
();
}
else
{
connect_with_options
(
opts
);
}
};
$
(
form_id
).
submit
(
function
(
event
){
event
.
preventDefault
();
connect
();
connect
_without_options
();
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment