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
98c4d9bd
Commit
98c4d9bd
authored
Nov 07, 2015
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
web terminal kill方法
parent
24730ebd
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
46 additions
and
14 deletions
+46
-14
connect.py
connect.py
+14
-8
views.py
jlog/views.py
+3
-2
jumpserver.conf
jumpserver.conf
+1
-1
run_websocket.py
run_websocket.py
+19
-0
log_online.html
templates/jlog/log_online.html
+9
-3
No files found.
connect.py
View file @
98c4d9bd
...
@@ -269,12 +269,7 @@ class Tty(object):
...
@@ -269,12 +269,7 @@ class Tty(object):
today_connect_log_dir
=
os
.
path
.
join
(
tty_log_dir
,
date_start
)
today_connect_log_dir
=
os
.
path
.
join
(
tty_log_dir
,
date_start
)
log_file_path
=
os
.
path
.
join
(
today_connect_log_dir
,
'
%
s_
%
s_
%
s'
%
(
self
.
username
,
self
.
asset_name
,
time_start
))
log_file_path
=
os
.
path
.
join
(
today_connect_log_dir
,
'
%
s_
%
s_
%
s'
%
(
self
.
username
,
self
.
asset_name
,
time_start
))
if
self
.
login_type
==
'ssh'
:
pid
=
os
.
getpid
()
remote_ip
=
os
.
popen
(
"who -m | awk '{ print $5 }'"
)
.
read
()
.
strip
(
'()
\n
'
)
else
:
pid
=
0
remote_ip
=
'Web'
try
:
try
:
is_dir
(
today_connect_log_dir
,
mode
=
0777
)
is_dir
(
today_connect_log_dir
,
mode
=
0777
)
...
@@ -287,8 +282,19 @@ class Tty(object):
...
@@ -287,8 +282,19 @@ class Tty(object):
except
IOError
:
except
IOError
:
raise
ServerError
(
'Create logfile failed, Please modify
%
s permission.'
%
today_connect_log_dir
)
raise
ServerError
(
'Create logfile failed, Please modify
%
s permission.'
%
today_connect_log_dir
)
log
=
Log
(
user
=
self
.
username
,
host
=
self
.
asset_name
,
remote_ip
=
remote_ip
,
if
self
.
login_type
==
'ssh'
:
log_path
=
log_file_path
,
start_time
=
datetime
.
datetime
.
now
(),
pid
=
pid
)
pid
=
os
.
getpid
()
remote_ip
=
os
.
popen
(
"who -m | awk '{ print $5 }'"
)
.
read
()
.
strip
(
'()
\n
'
)
log
=
Log
(
user
=
self
.
username
,
host
=
self
.
asset_name
,
remote_ip
=
remote_ip
,
log_path
=
log_file_path
,
start_time
=
datetime
.
datetime
.
now
(),
pid
=
pid
)
else
:
remote_ip
=
'Web'
log
=
Log
(
user
=
self
.
username
,
host
=
self
.
asset_name
,
remote_ip
=
remote_ip
,
log_path
=
log_file_path
,
start_time
=
datetime
.
datetime
.
now
(),
pid
=
0
)
log
.
save
()
log
.
pid
=
log
.
id
log
.
save
()
log_file_f
.
write
(
'Start at
%
s
\n
'
%
datetime
.
datetime
.
now
())
log_file_f
.
write
(
'Start at
%
s
\n
'
%
datetime
.
datetime
.
now
())
log
.
save
()
log
.
save
()
return
log_file_f
,
log_time_f
,
log
return
log_file_f
,
log_time_f
,
log
...
...
jlog/views.py
View file @
98c4d9bd
...
@@ -48,7 +48,8 @@ def log_list(request, offset):
...
@@ -48,7 +48,8 @@ def log_list(request, offset):
contact_list
,
p
,
contacts
,
page_range
,
current_page
,
show_first
,
show_end
=
pages
(
posts
,
request
)
contact_list
,
p
,
contacts
,
page_range
,
current_page
,
show_first
,
show_end
=
pages
(
posts
,
request
)
web_monitor_uri
=
'
%
s/monitor'
%
web_socket_host
web_monitor_uri
=
'ws://
%
s/monitor'
%
web_socket_host
web_kill_uri
=
'http://
%
s/kill'
%
web_socket_host
return
render_to_response
(
'jlog/log_
%
s.html'
%
offset
,
locals
(),
context_instance
=
RequestContext
(
request
))
return
render_to_response
(
'jlog/log_
%
s.html'
%
offset
,
locals
(),
context_instance
=
RequestContext
(
request
))
...
@@ -103,6 +104,6 @@ def log_record(request):
...
@@ -103,6 +104,6 @@ def log_record(request):
def
web_terminal
(
request
):
def
web_terminal
(
request
):
web_terminal_uri
=
'
%
s/terminal'
%
web_socket_host
web_terminal_uri
=
'
ws://
%
s/terminal'
%
web_socket_host
return
render_to_response
(
'jlog/web_terminal.html'
,
locals
())
return
render_to_response
(
'jlog/web_terminal.html'
,
locals
())
jumpserver.conf
View file @
98c4d9bd
...
@@ -23,7 +23,7 @@ root_pw = secret234
...
@@ -23,7 +23,7 @@ root_pw = secret234
[
websocket
]
[
websocket
]
web_socket_host
=
ws
://
192
.
168
.
244
.
129
:
3000
web_socket_host
=
192
.
168
.
244
.
129
:
3000
[
mail
]
[
mail
]
...
...
run_websocket.py
View file @
98c4d9bd
...
@@ -7,6 +7,7 @@ import os
...
@@ -7,6 +7,7 @@ import os
import
sys
import
sys
import
os.path
import
os.path
import
threading
import
threading
import
uuid
import
tornado.ioloop
import
tornado.ioloop
import
tornado.options
import
tornado.options
...
@@ -96,6 +97,7 @@ class Application(tornado.web.Application):
...
@@ -96,6 +97,7 @@ class Application(tornado.web.Application):
handlers
=
[
handlers
=
[
(
r'/monitor'
,
MonitorHandler
),
(
r'/monitor'
,
MonitorHandler
),
(
r'/terminal'
,
WebTerminalHandler
),
(
r'/terminal'
,
WebTerminalHandler
),
(
r'/kill'
,
WebTerminalKillHandler
),
]
]
setting
=
{
setting
=
{
...
@@ -165,8 +167,20 @@ class WebTty(Tty):
...
@@ -165,8 +167,20 @@ class WebTty(Tty):
self
.
input_mode
=
False
self
.
input_mode
=
False
class
WebTerminalKillHandler
(
tornado
.
web
.
RequestHandler
):
def
get
(
self
):
ws_id
=
self
.
get_argument
(
'id'
)
for
ws
in
WebTerminalHandler
.
clients
:
print
ws
.
id
if
ws
.
id
==
int
(
ws_id
):
print
"killed"
ws
.
close
()
print
len
(
WebTerminalHandler
.
clients
)
class
WebTerminalHandler
(
tornado
.
websocket
.
WebSocketHandler
):
class
WebTerminalHandler
(
tornado
.
websocket
.
WebSocketHandler
):
tasks
=
[]
tasks
=
[]
clients
=
[]
def
__init__
(
self
,
*
args
,
**
kwargs
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
self
.
term
=
None
self
.
term
=
None
...
@@ -174,6 +188,7 @@ class WebTerminalHandler(tornado.websocket.WebSocketHandler):
...
@@ -174,6 +188,7 @@ class WebTerminalHandler(tornado.websocket.WebSocketHandler):
self
.
log_file_f
=
None
self
.
log_file_f
=
None
self
.
log_time_f
=
None
self
.
log_time_f
=
None
self
.
log
=
None
self
.
log
=
None
self
.
id
=
0
super
(
WebTerminalHandler
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
super
(
WebTerminalHandler
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
def
check_origin
(
self
,
origin
):
def
check_origin
(
self
,
origin
):
...
@@ -184,6 +199,7 @@ class WebTerminalHandler(tornado.websocket.WebSocketHandler):
...
@@ -184,6 +199,7 @@ class WebTerminalHandler(tornado.websocket.WebSocketHandler):
self
.
term
.
get_connection
()
self
.
term
.
get_connection
()
self
.
channel
=
self
.
term
.
ssh
.
invoke_shell
(
term
=
'xterm'
)
self
.
channel
=
self
.
term
.
ssh
.
invoke_shell
(
term
=
'xterm'
)
WebTerminalHandler
.
tasks
.
append
(
MyThread
(
target
=
self
.
forward_outbound
))
WebTerminalHandler
.
tasks
.
append
(
MyThread
(
target
=
self
.
forward_outbound
))
WebTerminalHandler
.
clients
.
append
(
self
)
for
t
in
WebTerminalHandler
.
tasks
:
for
t
in
WebTerminalHandler
.
tasks
:
if
t
.
is_alive
():
if
t
.
is_alive
():
...
@@ -205,6 +221,8 @@ class WebTerminalHandler(tornado.websocket.WebSocketHandler):
...
@@ -205,6 +221,8 @@ class WebTerminalHandler(tornado.websocket.WebSocketHandler):
def
on_close
(
self
):
def
on_close
(
self
):
print
'On_close'
print
'On_close'
if
self
in
WebTerminalHandler
.
clients
:
WebTerminalHandler
.
clients
.
remove
(
self
)
self
.
log_file_f
.
write
(
'End time is
%
s'
%
datetime
.
datetime
.
now
())
self
.
log_file_f
.
write
(
'End time is
%
s'
%
datetime
.
datetime
.
now
())
self
.
log
.
is_finished
=
True
self
.
log
.
is_finished
=
True
self
.
log
.
end_time
=
datetime
.
datetime
.
now
()
self
.
log
.
end_time
=
datetime
.
datetime
.
now
()
...
@@ -213,6 +231,7 @@ class WebTerminalHandler(tornado.websocket.WebSocketHandler):
...
@@ -213,6 +231,7 @@ class WebTerminalHandler(tornado.websocket.WebSocketHandler):
def
forward_outbound
(
self
):
def
forward_outbound
(
self
):
self
.
log_file_f
,
self
.
log_time_f
,
self
.
log
=
self
.
term
.
get_log_file
()
self
.
log_file_f
,
self
.
log_time_f
,
self
.
log
=
self
.
term
.
get_log_file
()
self
.
id
=
self
.
log
.
id
try
:
try
:
data
=
''
data
=
''
pre_timestamp
=
time
.
time
()
pre_timestamp
=
time
.
time
()
...
...
templates/jlog/log_online.html
View file @
98c4d9bd
...
@@ -97,7 +97,7 @@
...
@@ -97,7 +97,7 @@
{% ifnotequal session_role_id 0 %}
{% ifnotequal session_role_id 0 %}
<td
class=
"text-center"
><a
href=
"/jlog/history/?id={{ post.id }}"
class=
"log_command"
>
命令统计
</a></td>
<td
class=
"text-center"
><a
href=
"/jlog/history/?id={{ post.id }}"
class=
"log_command"
>
命令统计
</a></td>
<td
class=
"text-center"
><a
class=
"monitor"
file_path=
"{{ post.log_path }}"
>
监控
</a></td>
<td
class=
"text-center"
><a
class=
"monitor"
file_path=
"{{ post.log_path }}"
>
监控
</a></td>
<td
class=
"text-center"
><input
type=
"button"
id=
"cut"
class=
"btn btn-danger btn-xs"
name=
"cut"
value=
"阻断"
onclick=
'cut("{{ post.pid }}")'
/></td>
<td
class=
"text-center"
><input
type=
"button"
id=
"cut"
class=
"btn btn-danger btn-xs"
name=
"cut"
value=
"阻断"
onclick=
'cut("{{ post.pid }}"
, "{{ post.remote_ip }}"
)'
/></td>
{% endifnotequal %}
{% endifnotequal %}
<td
class=
"text-center"
id=
"start_time"
>
{{ post.start_time|date:"Y-m-d H:i:s" }}
</td>
<td
class=
"text-center"
id=
"start_time"
>
{{ post.start_time|date:"Y-m-d H:i:s" }}
</td>
</tr>
</tr>
...
@@ -202,8 +202,14 @@
...
@@ -202,8 +202,14 @@
{
#
}
#
}
{
#
}
#
}
function
cut
(
num
){
function
cut
(
num
,
host
){
var
g_url
=
"/jlog/log_kill/?id="
+
num
;
console
.
log
(
host
);
if
(
host
==
'Web'
){
var
g_url
=
'{{ web_kill_uri }}'
+
'?id='
+
num
;
}
else
{
g_url
=
"/jlog/log_kill/?id="
+
num
;
}
$
.
ajax
({
$
.
ajax
({
type
:
"GET"
,
type
:
"GET"
,
url
:
g_url
,
url
:
g_url
,
...
...
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