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
4b90cd9b
Commit
4b90cd9b
authored
Mar 21, 2016
by
Astraeux
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3 from jumpserver/dev
update from origin
parents
4b53bae5
fcb3fd71
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
74 additions
and
65 deletions
+74
-65
connect.py
connect.py
+39
-28
requirements.txt
install/requirements.txt
+1
-2
models.py
jperm/models.py
+1
-1
perm_api.py
jperm/perm_api.py
+2
-1
views.py
jperm/views.py
+4
-4
jumpserver.conf
jumpserver.conf
+6
-6
run_server.py
run_server.py
+6
-6
webterminal.js
static/js/webterminal.js
+5
-5
log_online.html
templates/jlog/log_online.html
+1
-1
static.jinja2
templates/jlog/static.jinja2
+0
-0
perm_role_add.html
templates/jperm/perm_role_add.html
+4
-0
perm_role_edit.html
templates/jperm/perm_role_edit.html
+5
-1
perm_role_push.html
templates/jperm/perm_role_push.html
+0
-10
No files found.
connect.py
View file @
4b90cd9b
...
@@ -92,11 +92,20 @@ class Tty(object):
...
@@ -92,11 +92,20 @@ class Tty(object):
self
.
remote_ip
=
''
self
.
remote_ip
=
''
self
.
login_type
=
login_type
self
.
login_type
=
login_type
self
.
vim_flag
=
False
self
.
vim_flag
=
False
self
.
ps1_pattern
=
re
.
compile
(
'
\
[
.*@.*
\
]
[
\
$#]
\
s'
)
self
.
ps1_pattern
=
re
.
compile
(
'
\
[
?.*@.*
\
]?
[
\
$#]
\
s'
)
self
.
vim_pattern
=
re
.
compile
(
r'\W
vi[m]+\s.* | \W
fg\s.*'
,
re
.
X
)
self
.
vim_pattern
=
re
.
compile
(
r'\W
?vi[m]?\s.* | \W?
fg\s.*'
,
re
.
X
)
self
.
vim_data
=
''
self
.
vim_data
=
''
self
.
stream
=
pyte
.
ByteStream
()
self
.
stream
=
None
self
.
screen
=
None
self
.
screen
=
None
self
.
__init_screen_stream
()
def
__init_screen_stream
(
self
):
"""
初始化虚拟屏幕和字符流
"""
self
.
stream
=
pyte
.
ByteStream
()
self
.
screen
=
pyte
.
Screen
(
80
,
24
)
self
.
stream
.
attach
(
self
.
screen
)
@staticmethod
@staticmethod
def
is_output
(
strings
):
def
is_output
(
strings
):
...
@@ -125,30 +134,35 @@ class Tty(object):
...
@@ -125,30 +134,35 @@ class Tty(object):
result
=
match
[
-
1
]
.
strip
()
result
=
match
[
-
1
]
.
strip
()
return
result
return
result
def
deal_command
(
self
):
def
deal_command
(
self
,
data
):
"""
"""
处理截获的命令
处理截获的命令
:param data: 要处理的命令
:return:返回最后的处理结果
:return:返回最后的处理结果
"""
"""
command
=
''
command
=
''
# 从虚拟屏幕中获取处理后的数据
try
:
for
line
in
reversed
(
self
.
screen
.
buffer
):
self
.
stream
.
feed
(
data
)
line_data
=
""
.
join
(
map
(
operator
.
attrgetter
(
"data"
),
line
))
.
strip
()
# 从虚拟屏幕中获取处理后的数据
if
len
(
line_data
)
>
0
:
for
line
in
reversed
(
self
.
screen
.
buffer
):
parser_result
=
self
.
command_parser
(
line_data
)
line_data
=
""
.
join
(
map
(
operator
.
attrgetter
(
"data"
),
line
))
.
strip
()
if
parser_result
is
not
None
:
if
len
(
line_data
)
>
0
:
# 2个条件写一起会有错误的数据
parser_result
=
self
.
command_parser
(
line_data
)
if
len
(
parser_result
)
>
0
:
if
parser_result
is
not
None
:
command
=
parser_result
# 2个条件写一起会有错误的数据
else
:
if
len
(
parser_result
)
>
0
:
command
=
line_data
command
=
parser_result
break
else
:
if
command
!=
''
:
command
=
line_data
# 判断用户输入的是否是vim 或者fg命令
break
if
self
.
vim_pattern
.
search
(
command
):
if
command
!=
''
:
self
.
vim_flag
=
True
# 判断用户输入的是否是vim 或者fg命令
# 虚拟屏幕清空
if
self
.
vim_pattern
.
search
(
command
):
self
.
screen
.
reset
()
self
.
vim_flag
=
True
# 虚拟屏幕清空
self
.
screen
.
reset
()
except
Exception
:
pass
return
command
return
command
def
get_log
(
self
):
def
get_log
(
self
):
...
@@ -348,16 +362,15 @@ class SshTty(Tty):
...
@@ -348,16 +362,15 @@ class SshTty(Tty):
# 这个是用来处理用户的复制操作
# 这个是用来处理用户的复制操作
if
input_str
!=
x
:
if
input_str
!=
x
:
data
+=
input_str
data
+=
input_str
self
.
stream
.
feed
(
data
)
if
self
.
vim_flag
:
if
self
.
vim_flag
:
match
=
self
.
ps1_pattern
.
search
(
self
.
vim_data
)
match
=
self
.
ps1_pattern
.
search
(
self
.
vim_data
)
if
match
:
if
match
:
self
.
vim_flag
=
False
self
.
vim_flag
=
False
data
=
self
.
deal_command
()[
0
:
200
]
data
=
self
.
deal_command
(
data
)[
0
:
200
]
if
len
(
data
)
>
0
:
if
len
(
data
)
>
0
:
TtyLog
(
log
=
log
,
datetime
=
datetime
.
datetime
.
now
(),
cmd
=
data
)
.
save
()
TtyLog
(
log
=
log
,
datetime
=
datetime
.
datetime
.
now
(),
cmd
=
data
)
.
save
()
else
:
else
:
data
=
self
.
deal_command
()[
0
:
200
]
data
=
self
.
deal_command
(
data
)[
0
:
200
]
if
len
(
data
)
>
0
:
if
len
(
data
)
>
0
:
TtyLog
(
log
=
log
,
datetime
=
datetime
.
datetime
.
now
(),
cmd
=
data
)
.
save
()
TtyLog
(
log
=
log
,
datetime
=
datetime
.
datetime
.
now
(),
cmd
=
data
)
.
save
()
data
=
''
data
=
''
...
@@ -393,10 +406,8 @@ class SshTty(Tty):
...
@@ -393,10 +406,8 @@ class SshTty(Tty):
# 获取连接的隧道并设置窗口大小 Make a channel and set windows size
# 获取连接的隧道并设置窗口大小 Make a channel and set windows size
global
channel
global
channel
win_size
=
self
.
get_win_size
()
win_size
=
self
.
get_win_size
()
#self.channel = channel = ssh.invoke_shell(height=win_size[0], width=win_size[1], term='xterm')
#
self.channel = channel = ssh.invoke_shell(height=win_size[0], width=win_size[1], term='xterm')
self
.
channel
=
channel
=
transport
.
open_session
()
self
.
channel
=
channel
=
transport
.
open_session
()
self
.
screen
=
pyte
.
Screen
(
win_size
[
1
],
win_size
[
0
])
self
.
stream
.
attach
(
self
.
screen
)
channel
.
get_pty
(
term
=
'xterm'
,
height
=
win_size
[
0
],
width
=
win_size
[
1
])
channel
.
get_pty
(
term
=
'xterm'
,
height
=
win_size
[
0
],
width
=
win_size
[
1
])
channel
.
invoke_shell
()
channel
.
invoke_shell
()
try
:
try
:
...
...
install/requirements.txt
View file @
4b90cd9b
...
@@ -14,4 +14,4 @@ ansible==1.9.4
...
@@ -14,4 +14,4 @@ ansible==1.9.4
pyinotify==0.9.6
pyinotify==0.9.6
passlib==1.6.5
passlib==1.6.5
argparse==1.4.0
argparse==1.4.0
django_crontab==0.6.0
django_crontab==0.6.0
\ No newline at end of file
jperm/models.py
View file @
4b90cd9b
...
@@ -26,7 +26,7 @@ class PermSudo(models.Model):
...
@@ -26,7 +26,7 @@ class PermSudo(models.Model):
class
PermRole
(
models
.
Model
):
class
PermRole
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
100
,
unique
=
True
)
name
=
models
.
CharField
(
max_length
=
100
,
unique
=
True
)
comment
=
models
.
CharField
(
max_length
=
100
,
null
=
True
,
blank
=
True
,
default
=
''
)
comment
=
models
.
CharField
(
max_length
=
100
,
null
=
True
,
blank
=
True
,
default
=
''
)
password
=
models
.
CharField
(
max_length
=
1
00
)
password
=
models
.
CharField
(
max_length
=
1
28
)
key_path
=
models
.
CharField
(
max_length
=
100
)
key_path
=
models
.
CharField
(
max_length
=
100
)
date_added
=
models
.
DateTimeField
(
auto_now
=
True
)
date_added
=
models
.
DateTimeField
(
auto_now
=
True
)
sudo
=
models
.
ManyToManyField
(
PermSudo
,
related_name
=
'perm_role'
)
sudo
=
models
.
ManyToManyField
(
PermSudo
,
related_name
=
'perm_role'
)
...
...
jperm/perm_api.py
View file @
4b90cd9b
...
@@ -182,8 +182,9 @@ def gen_resource(ob, perm=None):
...
@@ -182,8 +182,9 @@ def gen_resource(ob, perm=None):
info
=
{
'hostname'
:
asset
.
hostname
,
info
=
{
'hostname'
:
asset
.
hostname
,
'ip'
:
asset
.
ip
,
'ip'
:
asset
.
ip
,
'port'
:
asset_info
.
get
(
'port'
,
22
),
'port'
:
asset_info
.
get
(
'port'
,
22
),
'ansible_ssh_private_key_file'
:
role_key
,
'username'
:
role
.
name
,
'username'
:
role
.
name
,
'password'
:
CRYPTOR
.
decrypt
(
role
.
password
)
#
'password': CRYPTOR.decrypt(role.password)
}
}
if
os
.
path
.
isfile
(
role_key
):
if
os
.
path
.
isfile
(
role_key
):
...
...
jperm/views.py
View file @
4b90cd9b
...
@@ -519,12 +519,12 @@ def perm_role_push(request):
...
@@ -519,12 +519,12 @@ def perm_role_push(request):
ret
[
"pass_push"
]
=
task
.
add_user
(
role
.
name
)
ret
[
"pass_push"
]
=
task
.
add_user
(
role
.
name
)
ret
[
"key_push"
]
=
task
.
push_key
(
role
.
name
,
os
.
path
.
join
(
role
.
key_path
,
'id_rsa.pub'
))
ret
[
"key_push"
]
=
task
.
push_key
(
role
.
name
,
os
.
path
.
join
(
role
.
key_path
,
'id_rsa.pub'
))
# 2. 推送账号密码
# 2. 推送账号密码
<为了安全 系统用户统一使用秘钥进行通信, 不再提供密码方式的推送>
elif
password_push
:
#
elif password_push:
ret
[
"pass_push"
]
=
task
.
add_user
(
role
.
name
,
CRYPTOR
.
decrypt
(
role
.
password
))
#
ret["pass_push"] = task.add_user(role.name, CRYPTOR.decrypt(role.password))
# 3. 推送sudo配置文件
# 3. 推送sudo配置文件
if
password_push
or
key_push
:
if
key_push
:
sudo_list
=
set
([
sudo
for
sudo
in
role
.
sudo
.
all
()])
# set(sudo1, sudo2, sudo3)
sudo_list
=
set
([
sudo
for
sudo
in
role
.
sudo
.
all
()])
# set(sudo1, sudo2, sudo3)
if
sudo_list
:
if
sudo_list
:
ret
[
'sudo'
]
=
task
.
push_sudo_file
([
role
],
sudo_list
)
ret
[
'sudo'
]
=
task
.
push_sudo_file
([
role
],
sudo_list
)
...
...
jumpserver.conf
View file @
4b90cd9b
[
base
]
[
base
]
url
=
http
://
192
.
168
.
244
.
129
url
=
http
://
192
.
168
.
10
.
165
key
=
i6k2zeu8x6mncl76
key
=
941
enj9neshd1wes
ip
=
0
.
0
.
0
.
0
ip
=
0
.
0
.
0
.
0
port
=
80
port
=
80
log
=
debug
log
=
debug
...
@@ -14,9 +14,9 @@ database = jumpserver
...
@@ -14,9 +14,9 @@ database = jumpserver
[
mail
]
[
mail
]
mail_enable
=
1
mail_enable
=
1
email_host
=
smtp
.
exmail
.
qq
.
com
email_host
=
email_port
=
25
email_port
=
587
email_host_user
=
noreply
@
jumpserver
.
org
email_host_user
=
email_host_password
=
xxxxxxxxxx
email_host_password
=
email_use_tls
=
True
email_use_tls
=
True
run_server.py
View file @
4b90cd9b
...
@@ -10,7 +10,6 @@ import os.path
...
@@ -10,7 +10,6 @@ import os.path
import
threading
import
threading
import
re
import
re
import
functools
import
functools
from
django.core.signals
import
request_started
,
request_finished
from
django.core.signals
import
request_started
,
request_finished
import
tornado.ioloop
import
tornado.ioloop
...
@@ -371,9 +370,10 @@ class WebTerminalHandler(tornado.websocket.WebSocketHandler):
...
@@ -371,9 +370,10 @@ class WebTerminalHandler(tornado.websocket.WebSocketHandler):
vim_data
=
self
.
term
.
deal_command
(
self
.
term
.
vim_data
)[
0
:
200
]
vim_data
=
self
.
term
.
deal_command
(
self
.
term
.
vim_data
)[
0
:
200
]
if
len
(
data
)
>
0
:
if
len
(
data
)
>
0
:
TtyLog
(
log
=
self
.
log
,
datetime
=
datetime
.
datetime
.
now
(),
cmd
=
vim_data
)
.
save
()
TtyLog
(
log
=
self
.
log
,
datetime
=
datetime
.
datetime
.
now
(),
cmd
=
vim_data
)
.
save
()
vim_data
=
self
.
term
.
deal_command
(
self
.
term
.
vim_data
)[
0
:
200
]
TtyLog
(
log
=
self
.
log
,
datetime
=
datetime
.
datetime
.
now
(),
if
len
(
vim_data
)
>
0
:
cmd
=
self
.
term
.
deal_command
(
self
.
term
.
data
)[
0
:
200
])
.
save
()
TtyLog
(
log
=
self
.
log
,
datetime
=
datetime
.
datetime
.
now
(),
cmd
=
vim_data
)
.
save
()
self
.
term
.
vim_data
=
''
self
.
term
.
vim_data
=
''
self
.
term
.
data
=
''
self
.
term
.
data
=
''
self
.
term
.
input_mode
=
False
self
.
term
.
input_mode
=
False
...
@@ -412,7 +412,7 @@ class WebTerminalHandler(tornado.websocket.WebSocketHandler):
...
@@ -412,7 +412,7 @@ class WebTerminalHandler(tornado.websocket.WebSocketHandler):
if
self
.
term
.
vim_flag
:
if
self
.
term
.
vim_flag
:
self
.
term
.
vim_data
+=
recv
self
.
term
.
vim_data
+=
recv
try
:
try
:
self
.
write_message
(
json
.
dumps
({
'data'
:
data
}
))
self
.
write_message
(
data
.
decode
(
'utf-8'
,
'replace'
))
now_timestamp
=
time
.
time
()
now_timestamp
=
time
.
time
()
self
.
log_time_f
.
write
(
'
%
s
%
s
\n
'
%
(
round
(
now_timestamp
-
pre_timestamp
,
4
),
len
(
data
)))
self
.
log_time_f
.
write
(
'
%
s
%
s
\n
'
%
(
round
(
now_timestamp
-
pre_timestamp
,
4
),
len
(
data
)))
self
.
log_file_f
.
write
(
data
)
self
.
log_file_f
.
write
(
data
)
...
@@ -460,7 +460,7 @@ def main():
...
@@ -460,7 +460,7 @@ def main():
}
}
tornado_app
=
tornado
.
web
.
Application
(
tornado_app
=
tornado
.
web
.
Application
(
[
[
(
r'/monitor'
,
MonitorHandler
),
(
r'/
ws/
monitor'
,
MonitorHandler
),
(
r'/ws/terminal'
,
WebTerminalHandler
),
(
r'/ws/terminal'
,
WebTerminalHandler
),
(
r'/kill'
,
WebTerminalKillHandler
),
(
r'/kill'
,
WebTerminalKillHandler
),
(
r'/ws/exec'
,
ExecHandler
),
(
r'/ws/exec'
,
ExecHandler
),
...
...
static/js/webterminal.js
View file @
4b90cd9b
/**
/**
* Created by liuzheng on 3/3/16.
* Created by liuzheng on 3/3/16.
*/
*/
...
@@ -35,13 +36,12 @@ WSSHClient.prototype.connect = function (options) {
...
@@ -35,13 +36,12 @@ WSSHClient.prototype.connect = function (options) {
};
};
this
.
_connection
.
onmessage
=
function
(
evt
)
{
this
.
_connection
.
onmessage
=
function
(
evt
)
{
var
data
=
JSON
.
parse
(
evt
.
data
.
toString
());
try
{
if
(
data
.
error
!==
undefined
)
{
options
.
onData
(
evt
.
data
);
}
catch
(
e
)
{
var
data
=
JSON
.
parse
(
evt
.
data
.
toString
());
options
.
onError
(
data
.
error
);
options
.
onError
(
data
.
error
);
}
}
else
{
options
.
onData
(
data
.
data
);
}
};
};
this
.
_connection
.
onclose
=
function
(
evt
)
{
this
.
_connection
.
onclose
=
function
(
evt
)
{
...
...
templates/jlog/log_online.html
View file @
4b90cd9b
...
@@ -136,7 +136,7 @@
...
@@ -136,7 +136,7 @@
var
protocol
=
'ws://'
;
var
protocol
=
'ws://'
;
}
}
var
endpoint
=
protocol
+
document
.
URL
.
match
(
RegExp
(
'//(.*?)/'
))[
1
]
+
'/monitor'
;
var
endpoint
=
protocol
+
document
.
URL
.
match
(
RegExp
(
'//(.*?)/'
))[
1
]
+
'/
ws/
monitor'
;
var
file_path
=
obj
.
attr
(
'file_path'
);
var
file_path
=
obj
.
attr
(
'file_path'
);
var
socket
=
new
WebSocket
(
endpoint
+
'?file_path='
+
file_path
);
var
socket
=
new
WebSocket
(
endpoint
+
'?file_path='
+
file_path
);
...
...
templates/jlog/static.jinja2
View file @
4b90cd9b
This diff is collapsed.
Click to expand it.
templates/jperm/perm_role_add.html
View file @
4b90cd9b
...
@@ -104,6 +104,10 @@ $('#roleForm').validator({
...
@@ -104,6 +104,10 @@ $('#roleForm').validator({
ok
:
""
,
ok
:
""
,
msg
:
{
required
:
"系统用户名称必填"
}
msg
:
{
required
:
"系统用户名称必填"
}
},
},
"role_password"
:
{
rule
:
"length[0~64]"
,
tip
:
"系统密码"
},
"role_key"
:
{
"role_key"
:
{
rule
:
"check_begin"
,
rule
:
"check_begin"
,
ok
:
""
,
ok
:
""
,
...
...
templates/jperm/perm_role_edit.html
View file @
4b90cd9b
...
@@ -105,12 +105,16 @@ $('#roleForm').validator({
...
@@ -105,12 +105,16 @@ $('#roleForm').validator({
tip
:
"输入系统用户名称"
,
tip
:
"输入系统用户名称"
,
ok
:
""
,
ok
:
""
,
msg
:
{
required
:
"系统用户名称必填"
}
msg
:
{
required
:
"系统用户名称必填"
}
},
"role_password"
:
{
rule
:
"length[0~64]"
,
tip
:
"系统密码"
},
},
"role_key"
:
{
"role_key"
:
{
rule
:
"check_begin"
,
rule
:
"check_begin"
,
ok
:
""
,
ok
:
""
,
empty
:
true
empty
:
true
}
,
}
},
},
valid
:
function
(
form
)
{
valid
:
function
(
form
)
{
...
...
templates/jperm/perm_role_push.html
View file @
4b90cd9b
...
@@ -74,16 +74,6 @@
...
@@ -74,16 +74,6 @@
</div>
</div>
</div>
</div>
</div>
</div>
<div
class=
"form-group"
>
<label
for=
"j_group"
class=
"col-sm-2 control-label"
>
使用密码
</label>
<div
class=
"col-sm-1"
>
<div
class=
"radio i-checks"
>
<label>
<input
type=
"checkbox"
value=
"1"
id=
"use_password"
name=
"use_password"
>
</label>
</div>
</div>
</div>
</div>
</div>
<div
class=
"hr-line-dashed"
></div>
<div
class=
"hr-line-dashed"
></div>
<div
class=
"form-group"
>
<div
class=
"form-group"
>
...
...
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