Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
J
jumpserver
Project
Project
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
ops
jumpserver
Commits
054edeef
Commit
054edeef
authored
Feb 29, 2016
by
黄成维
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
try fix tornado connection timeout
parent
5ab882ae
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
3 deletions
+21
-3
run_websocket.py
run_websocket.py
+21
-3
No files found.
run_websocket.py
View file @
054edeef
...
...
@@ -7,8 +7,10 @@ import os
import
sys
import
os.path
import
threading
import
datetime
import
re
import
functools
from
django.core.signals
import
request_started
,
request_finished
import
tornado.ioloop
import
tornado.options
...
...
@@ -20,10 +22,10 @@ import tornado.httpclient
from
tornado.websocket
import
WebSocketClosedError
from
tornado.options
import
define
,
options
from
pyinotify
import
WatchManager
,
Notifier
,
ProcessEvent
,
IN_DELETE
,
IN_CREATE
,
IN_MODIFY
,
AsyncNotifier
from
pyinotify
import
WatchManager
,
ProcessEvent
,
IN_DELETE
,
IN_CREATE
,
IN_MODIFY
,
AsyncNotifier
import
select
from
connect
import
Tty
,
User
,
Asset
,
PermRole
,
logger
,
get_object
,
PermRole
,
gen_resource
from
connect
import
Tty
,
User
,
Asset
,
PermRole
,
logger
,
get_object
,
gen_resource
from
connect
import
TtyLog
,
Log
,
Session
,
user_have_perm
,
get_group_user_perm
,
MyRunner
,
ExecLog
try
:
...
...
@@ -36,6 +38,16 @@ define("port", default=3000, help="run on the given port", type=int)
define
(
"host"
,
default
=
'0.0.0.0'
,
help
=
"run port on given host"
,
type
=
str
)
def
django_request_support
(
func
):
@functools.wraps
(
func
)
def
_deco
(
*
args
,
**
kwargs
):
request_started
.
send_robust
()
response
=
func
(
*
args
,
**
kwargs
)
request_finished
.
send_robust
()
return
response
return
_deco
def
require_auth
(
role
=
'user'
):
def
_deco
(
func
):
def
_deco2
(
request
,
*
args
,
**
kwargs
):
...
...
@@ -56,6 +68,7 @@ def require_auth(role='user'):
request
.
user
=
user
if
role
==
'admin'
:
if
user
.
role
in
[
'SU'
,
'GA'
]:
request_finished
.
send_robust
()
return
func
(
request
,
*
args
,
**
kwargs
)
logger
.
debug
(
'Websocket: user [
%
s ] is not admin.'
%
user
.
username
)
else
:
...
...
@@ -67,6 +80,7 @@ def require_auth(role='user'):
except
AttributeError
:
pass
logger
.
warning
(
'Websocket: Request auth failed.'
)
return
_deco2
return
_deco
...
...
@@ -127,6 +141,7 @@ class MonitorHandler(tornado.websocket.WebSocketHandler):
def
check_origin
(
self
,
origin
):
return
True
@django_request_support
@require_auth
(
'admin'
)
def
open
(
self
):
# 获取监控的path
...
...
@@ -178,6 +193,7 @@ class WebTty(Tty):
class
WebTerminalKillHandler
(
tornado
.
web
.
RequestHandler
):
@django_request_support
@require_auth
(
'admin'
)
def
get
(
self
):
ws_id
=
self
.
get_argument
(
'id'
)
...
...
@@ -207,6 +223,7 @@ class ExecHandler(tornado.websocket.WebSocketHandler):
def
check_origin
(
self
,
origin
):
return
True
@django_request_support
@require_auth
(
'user'
)
def
open
(
self
):
logger
.
debug
(
'Websocket: Open exec request'
)
...
...
@@ -287,6 +304,7 @@ class WebTerminalHandler(tornado.websocket.WebSocketHandler):
def
check_origin
(
self
,
origin
):
return
True
@django_request_support
@require_auth
(
'user'
)
def
open
(
self
):
logger
.
debug
(
'Websocket: Open request'
)
...
...
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