Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
coco
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
coco
Commits
212b5b04
Unverified
Commit
212b5b04
authored
Apr 30, 2019
by
老广
Committed by
GitHub
Apr 30, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #209 from jumpserver/dev
Dev
parents
93f247c0
2d89332f
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
73 additions
and
19 deletions
+73
-19
app.py
coco/app.py
+1
-1
connection.py
coco/connection.py
+1
-1
const.py
coco/const.py
+10
-0
connector.py
coco/httpd/elfinder/connector.py
+1
-1
sftp.py
coco/httpd/elfinder/volumes/sftp.py
+6
-8
proxy.py
coco/proxy.py
+10
-4
sftp.py
coco/sftp.py
+42
-2
coco.mo
locale/zh_CN/LC_MESSAGES/coco.mo
+0
-0
coco.po
locale/zh_CN/LC_MESSAGES/coco.po
+1
-1
requirements.txt
requirements/requirements.txt
+1
-1
No files found.
coco/app.py
View file @
212b5b04
...
@@ -23,7 +23,7 @@ from .session import Session
...
@@ -23,7 +23,7 @@ from .session import Session
from
.models
import
Connection
from
.models
import
Connection
__version__
=
'1.4.
9
'
__version__
=
'1.4.
10
'
BASE_DIR
=
os
.
path
.
dirname
(
os
.
path
.
dirname
(
__file__
))
BASE_DIR
=
os
.
path
.
dirname
(
os
.
path
.
dirname
(
__file__
))
logger
=
get_logger
(
__file__
)
logger
=
get_logger
(
__file__
)
...
...
coco/connection.py
View file @
212b5b04
...
@@ -157,7 +157,7 @@ class TelnetConnection:
...
@@ -157,7 +157,7 @@ class TelnetConnection:
password_pattern
=
re
.
compile
(
password_pattern
=
re
.
compile
(
r'Password:?\s*$|passwd:?\s*$|密\s*码:?\s*$'
,
re
.
I
r'Password:?\s*$|passwd:?\s*$|密\s*码:?\s*$'
,
re
.
I
)
)
success_pattern
=
re
.
compile
(
r'Last\s*login|success|成功|#|\$'
,
re
.
I
)
success_pattern
=
re
.
compile
(
r'Last\s*login|success|成功|#|
>|
\$'
,
re
.
I
)
custom_success_pattern
=
None
custom_success_pattern
=
None
def
__init__
(
self
,
asset
,
system_user
,
client
):
def
__init__
(
self
,
asset
,
system_user
,
client
):
...
...
coco/const.py
0 → 100644
View file @
212b5b04
# -*- coding: utf-8 -*-
#
#
# Permission actions choices
#
PERMS_ACTION_NAME_ALL
=
'all'
PERMS_ACTION_NAME_CONNECT
=
'connect'
PERMS_ACTION_NAME_UPLOAD_FILE
=
'upload_file'
PERMS_ACTION_NAME_DOWNLOAD_FILE
=
'download_file'
coco/httpd/elfinder/connector.py
View file @
212b5b04
...
@@ -109,8 +109,8 @@ class ElFinderConnector:
...
@@ -109,8 +109,8 @@ class ElFinderConnector:
try
:
try
:
func
()
func
()
except
Exception
as
e
:
except
Exception
as
e
:
logger
.
debug
(
e
,
exc_info
=
True
)
self
.
response
[
'error'
]
=
'
%
s'
%
e
self
.
response
[
'error'
]
=
'
%
s'
%
e
logger
.
error
(
e
,
exc_info
=
True
)
def
get_request_data
(
self
):
def
get_request_data
(
self
):
data_source
=
{}
data_source
=
{}
...
...
coco/httpd/elfinder/volumes/sftp.py
View file @
212b5b04
...
@@ -140,6 +140,7 @@ class SFTPVolume(BaseVolume):
...
@@ -140,6 +140,7 @@ class SFTPVolume(BaseVolume):
if
not
many
:
if
not
many
:
names
=
[
names
]
names
=
[
names
]
for
name
in
names
:
for
name
in
names
:
name
=
name
.
lstrip
(
self
.
path_sep
)
path
=
self
.
_join
(
parent_path
,
name
)
path
=
self
.
_join
(
parent_path
,
name
)
remote_path
=
self
.
_remote_path
(
path
)
remote_path
=
self
.
_remote_path
(
path
)
self
.
sftp
.
mkdir
(
remote_path
)
self
.
sftp
.
mkdir
(
remote_path
)
...
@@ -214,14 +215,11 @@ class SFTPVolume(BaseVolume):
...
@@ -214,14 +215,11 @@ class SFTPVolume(BaseVolume):
""" Delete a File or Directory object. """
""" Delete a File or Directory object. """
path
=
self
.
_path
(
target
)
path
=
self
.
_path
(
target
)
remote_path
=
self
.
_remote_path
(
path
)
remote_path
=
self
.
_remote_path
(
path
)
try
:
info
=
self
.
info
(
target
)
info
=
self
.
info
(
target
)
if
info
[
'mime'
]
==
'directory'
:
if
info
[
'mime'
]
==
'directory'
:
self
.
sftp
.
rmdir
(
remote_path
)
self
.
sftp
.
rmdir
(
remote_path
)
else
:
else
:
self
.
sftp
.
unlink
(
remote_path
)
self
.
sftp
.
unlink
(
remote_path
)
except
OSError
:
raise
OSError
(
"Delete {} failed"
.
format
(
self
.
_base_name
(
path
)))
return
target
return
target
def
upload_as_url
(
self
,
url
,
parent
):
def
upload_as_url
(
self
,
url
,
parent
):
...
...
coco/proxy.py
View file @
212b5b04
...
@@ -7,6 +7,7 @@ import time
...
@@ -7,6 +7,7 @@ import time
from
.session
import
Session
from
.session
import
Session
from
.models
import
Server
,
TelnetServer
from
.models
import
Server
,
TelnetServer
from
.const
import
PERMS_ACTION_NAME_CONNECT
from
.connection
import
SSHConnection
,
TelnetConnection
from
.connection
import
SSHConnection
,
TelnetConnection
from
.service
import
app_service
from
.service
import
app_service
from
.conf
import
config
from
.conf
import
config
...
@@ -93,15 +94,20 @@ class ProxyServer:
...
@@ -93,15 +94,20 @@ class ProxyServer:
验证用户是否有连接改资产的权限
验证用户是否有连接改资产的权限
:return: True or False
:return: True or False
"""
"""
return
app_service
.
validate_user_asset_permission
(
kwargs
=
{
self
.
client
.
user
.
id
,
self
.
asset
.
id
,
self
.
system_user
.
id
'user_id'
:
self
.
client
.
user
.
id
,
)
'asset_id'
:
self
.
asset
.
id
,
'system_user_id'
:
self
.
system_user
.
id
,
'action_name'
:
PERMS_ACTION_NAME_CONNECT
}
return
app_service
.
validate_user_asset_permission
(
**
kwargs
)
def
get_server_conn
(
self
):
def
get_server_conn
(
self
):
logger
.
info
(
"Connect to {}:{} ..."
.
format
(
self
.
asset
.
hostname
,
self
.
asset
.
port
))
logger
.
info
(
"Connect to {}:{} ..."
.
format
(
self
.
asset
.
hostname
,
self
.
asset
.
port
))
self
.
send_connecting_message
()
self
.
send_connecting_message
()
if
not
self
.
validate_permission
():
if
not
self
.
validate_permission
():
self
.
client
.
send_unicode
(
warning
(
_
(
'No permission'
)))
msg
=
_
(
'No permission'
)
self
.
client
.
send_unicode
(
warning
(
wr
(
msg
,
before
=
2
,
after
=
0
)))
server
=
None
server
=
None
elif
self
.
system_user
.
protocol
==
self
.
asset
.
protocol
==
'telnet'
:
elif
self
.
system_user
.
protocol
==
self
.
asset
.
protocol
==
'telnet'
:
server
=
self
.
get_telnet_server_conn
()
server
=
self
.
get_telnet_server_conn
()
...
...
coco/sftp.py
View file @
212b5b04
...
@@ -11,6 +11,10 @@ from coco.utils import get_logger
...
@@ -11,6 +11,10 @@ from coco.utils import get_logger
from
.conf
import
config
from
.conf
import
config
from
.service
import
app_service
from
.service
import
app_service
from
.connection
import
SSHConnection
from
.connection
import
SSHConnection
from
.const
import
(
PERMS_ACTION_NAME_DOWNLOAD_FILE
,
PERMS_ACTION_NAME_UPLOAD_FILE
,
PERMS_ACTION_NAME_ALL
,
)
CURRENT_DIR
=
os
.
path
.
dirname
(
__file__
)
CURRENT_DIR
=
os
.
path
.
dirname
(
__file__
)
logger
=
get_logger
(
__file__
)
logger
=
get_logger
(
__file__
)
...
@@ -267,11 +271,27 @@ class SFTPServer(paramiko.SFTPServerInterface):
...
@@ -267,11 +271,27 @@ class SFTPServer(paramiko.SFTPServerInterface):
def
lstat
(
self
,
path
):
def
lstat
(
self
,
path
):
return
self
.
stat
(
path
)
return
self
.
stat
(
path
)
@staticmethod
def
validate_permission
(
system_user
,
action
):
check_actions
=
[
PERMS_ACTION_NAME_ALL
,
action
]
granted_actions
=
getattr
(
system_user
,
'actions'
,
[])
actions
=
list
(
set
(
granted_actions
)
.
intersection
(
set
(
check_actions
)))
return
bool
(
actions
)
def
check_action
(
self
,
path
,
action
):
request
=
self
.
parse_path
(
path
)
host
,
su
=
request
[
'host'
],
request
[
'su'
]
system_user
=
self
.
hosts
.
get
(
host
,
{})
.
get
(
'system_users'
,
{})
.
get
(
su
)
if
not
system_user
:
raise
PermissionError
(
"No system user explicit"
)
if
not
self
.
validate_permission
(
system_user
,
action
):
raise
PermissionError
(
"Permission deny"
)
@convert_error
@convert_error
def
open
(
self
,
path
,
flags
,
attr
=
None
):
def
open
(
self
,
path
,
flags
,
attr
=
None
):
binary_flag
=
getattr
(
os
,
'O_BINARY'
,
0
)
binary_flag
=
getattr
(
os
,
'O_BINARY'
,
0
)
flags
|=
binary_flag
flags
|=
binary_flag
success
=
False
if
flags
&
os
.
O_WRONLY
:
if
flags
&
os
.
O_WRONLY
:
if
flags
&
os
.
O_APPEND
:
if
flags
&
os
.
O_APPEND
:
...
@@ -288,12 +308,17 @@ class SFTPServer(paramiko.SFTPServerInterface):
...
@@ -288,12 +308,17 @@ class SFTPServer(paramiko.SFTPServerInterface):
if
'r'
in
mode
:
if
'r'
in
mode
:
operate
=
"Download"
operate
=
"Download"
action
=
PERMS_ACTION_NAME_DOWNLOAD_FILE
elif
'a'
in
mode
:
elif
'a'
in
mode
:
operate
=
"Append"
operate
=
"Append"
action
=
PERMS_ACTION_NAME_UPLOAD_FILE
else
:
else
:
operate
=
"Upload"
operate
=
"Upload"
action
=
PERMS_ACTION_NAME_UPLOAD_FILE
success
=
False
try
:
try
:
self
.
check_action
(
path
,
action
)
client
,
rpath
=
self
.
get_sftp_client_rpath
(
path
)
client
,
rpath
=
self
.
get_sftp_client_rpath
(
path
)
f
=
client
.
open
(
rpath
,
mode
,
bufsize
=
4096
)
f
=
client
.
open
(
rpath
,
mode
,
bufsize
=
4096
)
f
.
prefetch
()
f
.
prefetch
()
...
@@ -309,6 +334,7 @@ class SFTPServer(paramiko.SFTPServerInterface):
...
@@ -309,6 +334,7 @@ class SFTPServer(paramiko.SFTPServerInterface):
@convert_error
@convert_error
def
remove
(
self
,
path
):
def
remove
(
self
,
path
):
self
.
check_action
(
path
,
action
=
PERMS_ACTION_NAME_UPLOAD_FILE
)
client
,
rpath
=
self
.
get_sftp_client_rpath
(
path
)
client
,
rpath
=
self
.
get_sftp_client_rpath
(
path
)
success
=
False
success
=
False
...
@@ -321,6 +347,7 @@ class SFTPServer(paramiko.SFTPServerInterface):
...
@@ -321,6 +347,7 @@ class SFTPServer(paramiko.SFTPServerInterface):
@convert_error
@convert_error
def
rename
(
self
,
src
,
dest
):
def
rename
(
self
,
src
,
dest
):
self
.
check_action
(
src
,
action
=
PERMS_ACTION_NAME_UPLOAD_FILE
)
client
,
rsrc
=
self
.
get_sftp_client_rpath
(
src
)
client
,
rsrc
=
self
.
get_sftp_client_rpath
(
src
)
client2
,
rdest
=
self
.
get_sftp_client_rpath
(
dest
)
client2
,
rdest
=
self
.
get_sftp_client_rpath
(
dest
)
success
=
False
success
=
False
...
@@ -338,6 +365,7 @@ class SFTPServer(paramiko.SFTPServerInterface):
...
@@ -338,6 +365,7 @@ class SFTPServer(paramiko.SFTPServerInterface):
@convert_error
@convert_error
def
mkdir
(
self
,
path
,
attr
=
0
o755
):
def
mkdir
(
self
,
path
,
attr
=
0
o755
):
self
.
check_action
(
path
,
action
=
PERMS_ACTION_NAME_UPLOAD_FILE
)
client
,
rpath
=
self
.
get_sftp_client_rpath
(
path
)
client
,
rpath
=
self
.
get_sftp_client_rpath
(
path
)
success
=
False
success
=
False
...
@@ -352,6 +380,7 @@ class SFTPServer(paramiko.SFTPServerInterface):
...
@@ -352,6 +380,7 @@ class SFTPServer(paramiko.SFTPServerInterface):
@convert_error
@convert_error
def
rmdir
(
self
,
path
):
def
rmdir
(
self
,
path
):
self
.
check_action
(
path
,
action
=
PERMS_ACTION_NAME_UPLOAD_FILE
)
client
,
rpath
=
self
.
get_sftp_client_rpath
(
path
)
client
,
rpath
=
self
.
get_sftp_client_rpath
(
path
)
success
=
False
success
=
False
...
@@ -405,10 +434,14 @@ class InternalSFTPClient(SFTPServer):
...
@@ -405,10 +434,14 @@ class InternalSFTPClient(SFTPServer):
client
,
rpath
=
self
.
get_sftp_client_rpath
(
path
)
client
,
rpath
=
self
.
get_sftp_client_rpath
(
path
)
if
'r'
in
mode
:
if
'r'
in
mode
:
operate
=
"Download"
operate
=
"Download"
action
=
PERMS_ACTION_NAME_DOWNLOAD_FILE
else
:
else
:
operate
=
"Upload"
operate
=
"Upload"
action
=
PERMS_ACTION_NAME_UPLOAD_FILE
success
=
False
success
=
False
try
:
try
:
self
.
check_action
(
path
,
action
=
action
)
f
=
client
.
open
(
rpath
,
mode
,
bufsize
=
4096
)
f
=
client
.
open
(
rpath
,
mode
,
bufsize
=
4096
)
success
=
True
success
=
True
return
f
return
f
...
@@ -423,6 +456,12 @@ class InternalSFTPClient(SFTPServer):
...
@@ -423,6 +456,12 @@ class InternalSFTPClient(SFTPServer):
attr
=
super
(
InternalSFTPClient
,
self
)
.
lstat
.
__wrapped__
(
self
,
path
)
attr
=
super
(
InternalSFTPClient
,
self
)
.
lstat
.
__wrapped__
(
self
,
path
)
return
attr
return
attr
def
rename
(
self
,
src
,
dest
):
return
super
(
InternalSFTPClient
,
self
)
.
rename
.
__wrapped__
(
self
,
src
,
dest
)
def
mkdir
(
self
,
path
,
attr
=
0
o755
):
return
super
(
InternalSFTPClient
,
self
)
.
mkdir
.
__wrapped__
(
self
,
path
,
attr
)
def
rmdir
(
self
,
path
):
def
rmdir
(
self
,
path
):
return
super
(
InternalSFTPClient
,
self
)
.
rmdir
.
__wrapped__
(
self
,
path
)
return
super
(
InternalSFTPClient
,
self
)
.
rmdir
.
__wrapped__
(
self
,
path
)
...
@@ -430,9 +469,10 @@ class InternalSFTPClient(SFTPServer):
...
@@ -430,9 +469,10 @@ class InternalSFTPClient(SFTPServer):
return
FakeChannel
.
new
()
return
FakeChannel
.
new
()
def
unlink
(
self
,
path
):
def
unlink
(
self
,
path
):
return
s
elf
.
remove
(
path
)
return
s
uper
(
InternalSFTPClient
,
self
)
.
remove
.
__wrapped__
(
self
,
path
)
def
putfo
(
self
,
f
,
path
,
callback
=
None
,
confirm
=
True
):
def
putfo
(
self
,
f
,
path
,
callback
=
None
,
confirm
=
True
):
self
.
check_action
(
path
,
action
=
PERMS_ACTION_NAME_UPLOAD_FILE
)
client
,
rpath
=
self
.
get_sftp_client_rpath
(
path
)
client
,
rpath
=
self
.
get_sftp_client_rpath
(
path
)
success
=
False
success
=
False
try
:
try
:
...
...
locale/zh_CN/LC_MESSAGES/coco.mo
View file @
212b5b04
No preview for this file type
locale/zh_CN/LC_MESSAGES/coco.po
View file @
212b5b04
...
@@ -83,7 +83,7 @@ msgstr "{T}7) 输入 {green}h{end} 帮助.{R}"
...
@@ -83,7 +83,7 @@ msgstr "{T}7) 输入 {green}h{end} 帮助.{R}"
#: coco/interactive.py:96
#: coco/interactive.py:96
#, python-brace-format
#, python-brace-format
msgid "{T}8) Enter {green}r{end} to refresh your assets and nodes.{R}"
msgid "{T}8) Enter {green}r{end} to refresh your assets and nodes.{R}"
msgstr "{T}
0
) 输入 {green}r{end} 刷新最新的机器和节点信息.{R}"
msgstr "{T}
8
) 输入 {green}r{end} 刷新最新的机器和节点信息.{R}"
#: coco/interactive.py:97
#: coco/interactive.py:97
#, python-brace-format
#, python-brace-format
...
...
requirements/requirements.txt
View file @
212b5b04
...
@@ -19,7 +19,7 @@ itsdangerous==0.24
...
@@ -19,7 +19,7 @@ itsdangerous==0.24
Jinja2==2.10
Jinja2==2.10
jmespath==0.9.3
jmespath==0.9.3
jms-storage==0.0.22
jms-storage==0.0.22
jumpserver-python-sdk==0.0.5
7
jumpserver-python-sdk==0.0.5
8
MarkupSafe==1.0
MarkupSafe==1.0
oss2==2.4.0
oss2==2.4.0
paramiko==2.4.1
paramiko==2.4.1
...
...
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