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
ebe8ce71
Commit
ebe8ce71
authored
Nov 02, 2015
by
ibuler@qq.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
some
parent
73f94fec
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
172 additions
and
0 deletions
+172
-0
run_log_watch.py
run_log_watch.py
+67
-0
log_watch.html
templates/log_watch.html
+105
-0
No files found.
run_log_watch.py
0 → 100644
View file @
ebe8ce71
# coding: utf-8
import
time
import
json
import
os.path
import
tornado.ioloop
import
tornado.options
import
tornado.web
import
tornado.websocket
import
tornado.httpserver
from
tornado.options
import
define
,
options
define
(
"port"
,
default
=
8080
,
help
=
"run on the given port"
,
type
=
int
)
class
Application
(
tornado
.
web
.
Application
):
def
__init__
(
self
):
handlers
=
[
(
r'/'
,
MainHandler
),
(
r'/send'
,
SendHandler
),
]
setting
=
{
'cookie_secret'
:
'DFksdfsasdfkasdfFKwlwfsdfsa1204mx'
,
'template_path'
:
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'templates'
),
'static_path'
:
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'static'
),
}
tornado
.
web
.
Application
.
__init__
(
self
,
handlers
,
**
setting
)
class
SendHandler
(
tornado
.
websocket
.
WebSocketHandler
):
clients
=
set
()
def
open
(
self
):
SendHandler
.
clients
.
add
(
self
)
self
.
write_message
(
json
.
dumps
({
'input'
:
'connected...'
}))
self
.
stream
.
set_nodelay
(
True
)
def
on_message
(
self
,
message
):
message
=
json
.
loads
(
message
)
self
.
write_message
(
json
.
dumps
({
'input'
:
'response...'
}))
while
True
:
self
.
write_message
(
json
.
dumps
(
message
))
time
.
sleep
(
1
)
# # 服务器主动关闭
# self.close()
# SendHandler.clients.remove(self)
def
on_close
(
self
):
# 客户端主动关闭
SendHandler
.
clients
.
remove
(
self
)
class
MainHandler
(
tornado
.
web
.
RequestHandler
):
def
get
(
self
):
self
.
render
(
'log_watch.html'
)
if
__name__
==
'__main__'
:
tornado
.
options
.
parse_command_line
()
app
=
Application
()
server
=
tornado
.
httpserver
.
HTTPServer
(
app
)
server
.
listen
(
options
.
port
)
tornado
.
ioloop
.
IOLoop
.
instance
()
.
start
()
templates/log_watch.html
0 → 100644
View file @
ebe8ce71
<html>
<head>
<link
href=
"http://cdn.bootcss.com/bootstrap/3.2.0/css/bootstrap.min.css"
rel=
"stylesheet"
>
<link
href=
"http://cdn.bootcss.com/bootstrap/3.2.0/css/bootstrap-theme.min.css"
rel=
"stylesheet"
>
<script
src=
"http://cdn.bootcss.com/jquery/2.1.1/jquery.min.js"
></script>
<script
src=
"http://cdn.bootcss.com/bootstrap/3.2.0/js/bootstrap.min.js"
></script>
<script>
var
wsUri
=
"ws://j:8080/send"
;
var
ws
;
function
connect
(){
ws
=
new
WebSocket
(
wsUri
);
ws
.
onopen
=
function
(
evt
){
console
.
log
(
evt
.
data
)
};
ws
.
onclose
=
function
(
evt
){
console
.
log
(
evt
.
data
)
};
ws
.
onmessage
=
function
(
evt
){
console
.
log
(
evt
.
data
)
};
ws
.
onerror
=
function
(
evt
){
console
.
log
(
evt
.
data
)
};
return
ws
;
}
function
send
()
{
var
data
=
{
input
:
$
(
"#input_data"
).
val
()
};
console
.
log
(
'hello'
);
ws
.
send
(
JSON
.
stringify
(
data
));
$
(
"#message"
).
empty
();
ws
.
onopen
=
function
()
{
ws
.
send
(
JSON
.
stringify
(
data
));
};
$
(
"#message"
).
append
(
'<div class="panel-body"><p>'
);
ws
.
onmessage
=
function
(
event
)
{
$
(
"#message"
).
append
(
JSON
.
parse
(
event
.
data
).
input
+
"<br>"
);
};
ws
.
onclose
=
function
(
event
)
{
$
(
"#message"
).
append
(
'</p></div>'
);
};
}
{
#
function
send
()
{
#
}
{
#
var
ws
=
new
WebSocket
(
"ws://j:8080/send"
);
#
}
{
##
}
{
#
var
data
=
{
#
}
{
#
input
:
$
(
"#input_data"
).
val
(),
#
}
{
#
};
#
}
{
##
}
{
#
$
(
"#message"
).
empty
();
#
}
{
#
ws
.
onopen
=
function
()
{
#
}
{
#
ws
.
send
(
JSON
.
stringify
(
data
));
#
}
{
#
};
#
}
{
##
}
{
#
$
(
"#message"
).
append
(
'<div class="panel-body"><p>'
);
#
}
{
#
ws
.
onmessage
=
function
(
event
)
{
#
}
{
#
$
(
"#message"
).
append
(
JSON
.
parse
(
event
.
data
).
input
+
"<br>"
);
#
}
{
#
};
#
}
{
##
}
{
#
ws
.
onclose
=
function
(
event
)
{
#
}
{
#
$
(
"#message"
).
append
(
'</p></div>'
);
#
}
{
#
};
#
}
{
#
}
#
}
function
disconnect
(){
ws
.
close
();
}
</script>
</head>
<body>
<div
id=
"test"
>
<form
class=
"form-horizontal"
role=
"form"
>
<div
class=
"panel panel-default"
>
<div
class=
"panel-heading"
>
<h5
class=
"panel-title"
>
>>输入
</h5>
</div>
<div
class=
"panel-body"
>
<div
class=
"form-group"
>
<div
class=
"col-md-8"
>
<input
type=
"text"
class=
"form-control"
id=
"input_data"
value=
""
>
</div>
</div>
<div
class=
"form-group"
>
<div
class=
"col-md-8"
>
<input
type=
"button"
class=
"btn btn-success"
id=
"input_1_btn"
onclick=
"connect();"
value=
"连接"
/>
<input
type=
"button"
class=
"btn btn-success"
id=
"input_btn"
onclick=
"send();"
value=
"发送"
/>
<input
type=
"button"
class=
"btn btn-success"
id=
"input_2_btn"
onclick=
"close();"
value=
"关闭"
/>
</div>
</div>
</div>
</div>
</form>
<div
class=
"panel panel-default"
>
<div
class=
"panel-heading"
>
<h5
class=
"panel-title"
>
>> 输出
</h5>
</div>
<div
class=
"panel-body"
>
<div
id=
"message"
></div>
</div>
</div>
</body>
</html>
</html>
\ No newline at end of file
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