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
9 years ago
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
web terminal kill方法
parent
24730ebd
master
auditor_jym
audits
dev
dev_beta
dev_beta_db
gengmei
lagacy-0.4.0
node_service
password
rbac
restrict_access
test
v52
wph
1.5.2
1.5.1
1.5.0
1.4.10
1.4.9
1.4.8
1.4.7
1.4.6
1.4.5
1.4.4
1.4.3
1.4.2
1.4.1
1.4.0
1.3.3
1.3.2
1.3.1
1.3.0
1.2.1
1.2.0
1.1.1
1.1.0
1.0.0
0.3.3
0.3.2
0.3.2-rc2
0.3.1
0.3.0-beta
v1.4.10
v1.4.7
v1.4.4
No related merge requests found
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
44 additions
and
12 deletions
+44
-12
connect.py
connect.py
+12
-6
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):
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
))
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
:
is_dir
(
today_connect_log_dir
,
mode
=
0777
)
...
...
@@ -287,8 +282,19 @@ class Tty(object):
except
IOError
:
raise
ServerError
(
'Create logfile failed, Please modify
%
s permission.'
%
today_connect_log_dir
)
if
self
.
login_type
==
'ssh'
:
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
.
save
()
return
log_file_f
,
log_time_f
,
log
...
...
This diff is collapsed.
Click to expand it.
jlog/views.py
View file @
98c4d9bd
...
...
@@ -48,7 +48,8 @@ def log_list(request, offset):
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
))
...
...
@@ -103,6 +104,6 @@ def log_record(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
())
This diff is collapsed.
Click to expand it.
jumpserver.conf
View file @
98c4d9bd
...
...
@@ -23,7 +23,7 @@ root_pw = secret234
[
websocket
]
web_socket_host
=
ws
://
192
.
168
.
244
.
129
:
3000
web_socket_host
=
192
.
168
.
244
.
129
:
3000
[
mail
]
...
...
This diff is collapsed.
Click to expand it.
run_websocket.py
View file @
98c4d9bd
...
...
@@ -7,6 +7,7 @@ import os
import
sys
import
os.path
import
threading
import
uuid
import
tornado.ioloop
import
tornado.options
...
...
@@ -96,6 +97,7 @@ class Application(tornado.web.Application):
handlers
=
[
(
r'/monitor'
,
MonitorHandler
),
(
r'/terminal'
,
WebTerminalHandler
),
(
r'/kill'
,
WebTerminalKillHandler
),
]
setting
=
{
...
...
@@ -165,8 +167,20 @@ class WebTty(Tty):
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
):
tasks
=
[]
clients
=
[]
def
__init__
(
self
,
*
args
,
**
kwargs
):
self
.
term
=
None
...
...
@@ -174,6 +188,7 @@ class WebTerminalHandler(tornado.websocket.WebSocketHandler):
self
.
log_file_f
=
None
self
.
log_time_f
=
None
self
.
log
=
None
self
.
id
=
0
super
(
WebTerminalHandler
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
def
check_origin
(
self
,
origin
):
...
...
@@ -184,6 +199,7 @@ class WebTerminalHandler(tornado.websocket.WebSocketHandler):
self
.
term
.
get_connection
()
self
.
channel
=
self
.
term
.
ssh
.
invoke_shell
(
term
=
'xterm'
)
WebTerminalHandler
.
tasks
.
append
(
MyThread
(
target
=
self
.
forward_outbound
))
WebTerminalHandler
.
clients
.
append
(
self
)
for
t
in
WebTerminalHandler
.
tasks
:
if
t
.
is_alive
():
...
...
@@ -205,6 +221,8 @@ class WebTerminalHandler(tornado.websocket.WebSocketHandler):
def
on_close
(
self
):
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
.
is_finished
=
True
self
.
log
.
end_time
=
datetime
.
datetime
.
now
()
...
...
@@ -213,6 +231,7 @@ class WebTerminalHandler(tornado.websocket.WebSocketHandler):
def
forward_outbound
(
self
):
self
.
log_file_f
,
self
.
log_time_f
,
self
.
log
=
self
.
term
.
get_log_file
()
self
.
id
=
self
.
log
.
id
try
:
data
=
''
pre_timestamp
=
time
.
time
()
...
...
This diff is collapsed.
Click to expand it.
templates/jlog/log_online.html
View file @
98c4d9bd
...
...
@@ -97,7 +97,7 @@
{% 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
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 %}
<td
class=
"text-center"
id=
"start_time"
>
{{ post.start_time|date:"Y-m-d H:i:s" }}
</td>
</tr>
...
...
@@ -202,8 +202,14 @@
{
#
}
#
}
function
cut
(
num
){
var
g_url
=
"/jlog/log_kill/?id="
+
num
;
function
cut
(
num
,
host
){
console
.
log
(
host
);
if
(
host
==
'Web'
){
var
g_url
=
'{{ web_kill_uri }}'
+
'?id='
+
num
;
}
else
{
g_url
=
"/jlog/log_kill/?id="
+
num
;
}
$
.
ajax
({
type
:
"GET"
,
url
:
g_url
,
...
...
This diff is collapsed.
Click to expand it.
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