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
e94c8463
Commit
e94c8463
authored
Oct 16, 2018
by
Sheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added default handler NotFoundHandler
parent
499f3b6d
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
9 deletions
+31
-9
test_app.py
tests/test_app.py
+7
-2
handler.py
webssh/handler.py
+22
-6
main.py
webssh/main.py
+2
-1
No files found.
tests/test_app.py
View file @
e94c8463
...
@@ -497,8 +497,13 @@ class TestAppInDebug(OtherTestBase):
...
@@ -497,8 +497,13 @@ class TestAppInDebug(OtherTestBase):
self
.
assertEqual
(
response
.
code
,
500
)
self
.
assertEqual
(
response
.
code
,
500
)
self
.
assertIn
(
b
'Uncaught exception'
,
response
.
body
)
self
.
assertIn
(
b
'Uncaught exception'
,
response
.
body
)
def
test_server_error
(
self
):
def
test_server_error_for_post_method
(
self
):
response
=
self
.
fetch
(
'/?error=generate'
,
method
=
'GET'
)
response
=
self
.
fetch
(
'/'
,
method
=
'POST'
,
body
=
urlencode
(
dict
(
self
.
body
,
error
=
'raise'
)),
headers
=
self
.
headers
)
self
.
assert_response
(
b
'"status": "Internal Server Error"'
,
response
)
self
.
assert_response
(
b
'"status": "Internal Server Error"'
,
response
)
def
test_html
(
self
):
def
test_html
(
self
):
...
...
webssh/handler.py
View file @
e94c8463
...
@@ -54,11 +54,15 @@ class MixinHandler(object):
...
@@ -54,11 +54,15 @@ class MixinHandler(object):
lst
=
context
.
trusted_downstream
lst
=
context
.
trusted_downstream
if
lst
and
ip
not
in
lst
:
if
lst
and
ip
not
in
lst
:
logging
.
info
(
'IP {!r} not found in trusted downstream {!r}'
.
format
(
ip
,
lst
)
)
return
True
return
True
if
context
.
_orig_protocol
==
'http'
:
if
context
.
_orig_protocol
==
'http'
:
ipaddr
=
to_ip_address
(
ip
)
ipaddr
=
to_ip_address
(
ip
)
if
not
ipaddr
.
is_private
:
if
not
ipaddr
.
is_private
:
logging
.
info
(
'Public non-https request is forbidden.'
)
return
True
return
True
def
set_default_headers
(
self
):
def
set_default_headers
(
self
):
...
@@ -93,6 +97,16 @@ class MixinHandler(object):
...
@@ -93,6 +97,16 @@ class MixinHandler(object):
return
(
ip
,
port
)
return
(
ip
,
port
)
class
NotFoundHandler
(
MixinHandler
,
tornado
.
web
.
ErrorHandler
):
def
initialize
(
self
):
pass
def
prepare
(
self
):
super
(
NotFoundHandler
,
self
)
.
prepare
()
raise
tornado
.
web
.
HTTPError
(
404
)
class
IndexHandler
(
MixinHandler
,
tornado
.
web
.
RequestHandler
):
class
IndexHandler
(
MixinHandler
,
tornado
.
web
.
RequestHandler
):
def
initialize
(
self
,
loop
,
policy
,
host_keys_settings
):
def
initialize
(
self
,
loop
,
policy
,
host_keys_settings
):
...
@@ -101,11 +115,12 @@ class IndexHandler(MixinHandler, tornado.web.RequestHandler):
...
@@ -101,11 +115,12 @@ class IndexHandler(MixinHandler, tornado.web.RequestHandler):
self
.
host_keys_settings
=
host_keys_settings
self
.
host_keys_settings
=
host_keys_settings
self
.
ssh_client
=
self
.
get_ssh_client
()
self
.
ssh_client
=
self
.
get_ssh_client
()
self
.
privatekey_filename
=
None
self
.
privatekey_filename
=
None
self
.
debug
=
self
.
settings
.
get
(
'debug'
,
False
)
self
.
result
=
dict
(
id
=
None
,
status
=
None
,
encoding
=
None
)
self
.
result
=
dict
(
id
=
None
,
status
=
None
,
encoding
=
None
)
def
write_error
(
self
,
status_code
,
**
kwargs
):
def
write_error
(
self
,
status_code
,
**
kwargs
):
if
not
swallow_http_errors
:
if
self
.
request
.
method
!=
'POST'
or
not
swallow_http_errors
:
super
(
Mixin
Handler
,
self
)
.
write_error
(
status_code
,
**
kwargs
)
super
(
Index
Handler
,
self
)
.
write_error
(
status_code
,
**
kwargs
)
else
:
else
:
exc_info
=
kwargs
.
get
(
'exc_info'
)
exc_info
=
kwargs
.
get
(
'exc_info'
)
if
exc_info
:
if
exc_info
:
...
@@ -269,13 +284,14 @@ class IndexHandler(MixinHandler, tornado.web.RequestHandler):
...
@@ -269,13 +284,14 @@ class IndexHandler(MixinHandler, tornado.web.RequestHandler):
future
.
set_result
(
worker
)
future
.
set_result
(
worker
)
def
get
(
self
):
def
get
(
self
):
debug
=
self
.
settings
.
get
(
'debug'
,
False
)
self
.
render
(
'index.html'
,
debug
=
self
.
debug
)
if
debug
and
self
.
get_argument
(
'error'
,
u''
):
raise
ValueError
(
'Uncaught exception'
)
self
.
render
(
'index.html'
,
debug
=
debug
)
@tornado.gen.coroutine
@tornado.gen.coroutine
def
post
(
self
):
def
post
(
self
):
if
self
.
debug
and
self
.
get_argument
(
'error'
,
u''
):
# for testing purpose only
raise
ValueError
(
'Uncaught exception'
)
future
=
Future
()
future
=
Future
()
t
=
threading
.
Thread
(
target
=
self
.
ssh_connect_wrapped
,
args
=
(
future
,))
t
=
threading
.
Thread
(
target
=
self
.
ssh_connect_wrapped
,
args
=
(
future
,))
t
.
setDaemon
(
True
)
t
.
setDaemon
(
True
)
...
...
webssh/main.py
View file @
e94c8463
...
@@ -3,7 +3,7 @@ import tornado.web
...
@@ -3,7 +3,7 @@ import tornado.web
import
tornado.ioloop
import
tornado.ioloop
from
tornado.options
import
options
from
tornado.options
import
options
from
webssh.handler
import
IndexHandler
,
WsockHandler
from
webssh.handler
import
IndexHandler
,
WsockHandler
,
NotFoundHandler
from
webssh.settings
import
(
from
webssh.settings
import
(
get_app_settings
,
get_host_keys_settings
,
get_policy_setting
,
get_app_settings
,
get_host_keys_settings
,
get_policy_setting
,
get_ssl_context
,
get_server_settings
get_ssl_context
,
get_server_settings
...
@@ -23,6 +23,7 @@ def make_handlers(loop, options):
...
@@ -23,6 +23,7 @@ def make_handlers(loop, options):
def
make_app
(
handlers
,
settings
):
def
make_app
(
handlers
,
settings
):
settings
.
update
(
default_handler_class
=
NotFoundHandler
)
return
tornado
.
web
.
Application
(
handlers
,
**
settings
)
return
tornado
.
web
.
Application
(
handlers
,
**
settings
)
...
...
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