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
784af494
Commit
784af494
authored
Dec 23, 2018
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 支持py2
parent
a2515aac
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
60 additions
and
30 deletions
+60
-30
connection.py
coco/connection.py
+6
-2
__init__.py
coco/httpd/elfinder/__init__.py
+2
-0
base.py
coco/httpd/elfinder/volumes/base.py
+2
-0
sftp.py
coco/httpd/elfinder/volumes/sftp.py
+2
-0
ws.py
coco/httpd/ws.py
+1
-1
interactive.py
coco/interactive.py
+3
-2
models.py
coco/models.py
+8
-8
recorder.py
coco/recorder.py
+13
-4
session.py
coco/session.py
+5
-1
sftp.py
coco/sftp.py
+1
-1
sshd.py
coco/sshd.py
+1
-1
struct.py
coco/struct.py
+3
-3
utils.py
coco/utils.py
+7
-2
cocod
cocod
+6
-5
No files found.
coco/connection.py
View file @
784af494
...
...
@@ -4,9 +4,13 @@
import
os
import
re
import
socket
import
selectors
import
telnetlib
try
:
import
selectors
except
ImportError
:
import
selectors2
as
selectors
import
paramiko
from
paramiko.ssh_exception
import
SSHException
...
...
@@ -82,7 +86,7 @@ class SSHConnection:
password_short
,
key_fingerprint
,
))
return
None
,
None
,
str
(
e
)
except
(
socket
.
error
,
TimeoutError
)
as
e
:
except
(
socket
.
error
,
socket
.
timeout
)
as
e
:
return
None
,
None
,
str
(
e
)
return
ssh
,
sock
,
None
...
...
coco/httpd/elfinder/__init__.py
0 → 100644
View file @
784af494
# -*- coding: utf-8 -*-
#
coco/httpd/elfinder/volumes/base.py
View file @
784af494
# -*- coding: utf-8 -*-
#
import
base64
import
os
import
hashlib
...
...
coco/httpd/elfinder/volumes/sftp.py
View file @
784af494
# -*- coding: utf-8 -*-
#
import
stat
import
threading
...
...
coco/httpd/ws.py
View file @
784af494
...
...
@@ -28,7 +28,7 @@ class ProxyNamespace(BaseNamespace):
...
}
"""
super
()
.
__init__
(
*
args
,
**
kwargs
)
super
(
BaseNamespace
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
self
.
win_size
=
None
def
new_connection
(
self
):
...
...
coco/interactive.py
View file @
784af494
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
from
__future__
import
unicode_literals
import
socket
import
threading
...
...
@@ -362,7 +363,7 @@ class InteractiveServer:
if
not
result
and
(
result_list
is
self
.
assets_list
)
and
self
.
finish
and
self
.
total_assets
==
0
:
# 无授权资产
return
None
,
None
return
elif
not
result
and
(
result_list
is
self
.
assets_list
)
and
self
.
finish
:
# 上一页是最后一页
...
...
@@ -383,7 +384,7 @@ class InteractiveServer:
action
=
yield
(
page
,
result
)
if
action
==
BACK
:
return
None
,
None
return
elif
action
==
PAGE_UP
:
if
page
<=
1
:
# 已经是第一页了
...
...
coco/models.py
View file @
784af494
...
...
@@ -8,14 +8,14 @@ from .service import app_service
from
.struct
import
SizedList
,
SelectEvent
from
.utils
import
wrap_with_line_feed
as
wr
,
wrap_with_warning
as
warning
,
\
ugettext
as
_
from
.
import
char
from
.
import
utils
from
.
import
char
,
utils
from
.
compat
import
str
BUF_SIZE
=
4096
logger
=
utils
.
get_logger
(
__file__
)
class
Connection
:
class
Connection
(
object
)
:
connections
=
{}
clients_num
=
0
...
...
@@ -88,7 +88,7 @@ class Connection:
return
cls
.
connections
.
get
(
cid
)
class
Request
:
class
Request
(
object
)
:
def
__init__
(
self
):
self
.
type
=
None
self
.
x11
=
None
...
...
@@ -96,7 +96,7 @@ class Request:
self
.
meta
=
{
'env'
:
{}}
class
Client
:
class
Client
(
object
)
:
"""
Client is the request client. Nothing more to say
...
...
@@ -143,12 +143,12 @@ class Client:
return
"<
%
s from
%
s:
%
s>"
%
(
self
.
user
,
self
.
addr
[
0
],
self
.
addr
[
1
])
class
ServerFilter
:
class
ServerFilter
(
object
)
:
def
run
(
self
,
data
):
pass
class
BaseServer
:
class
BaseServer
(
object
)
:
"""
Base Server
Achieve command record
...
...
@@ -383,7 +383,7 @@ class Server(BaseServer):
self
.
sock
.
transport
.
close
()
class
WSProxy
:
class
WSProxy
(
object
)
:
def
__init__
(
self
,
ws
,
client_id
):
self
.
ws
=
ws
self
.
client_id
=
client_id
...
...
coco/recorder.py
View file @
784af494
...
...
@@ -21,12 +21,12 @@ logger = get_logger(__file__)
BUF_SIZE
=
1024
class
ReplayRecorder
(
metaclass
=
abc
.
ABCMeta
):
class
ReplayRecorder
(
object
):
time_start
=
None
storage
=
None
def
__init__
(
self
):
super
()
.
__init__
()
super
(
ReplayRecorder
,
self
)
.
__init__
()
self
.
file
=
None
self
.
file_path
=
None
self
.
get_storage
()
...
...
@@ -110,14 +110,23 @@ class ReplayRecorder(metaclass=abc.ABCMeta):
return
self
.
finish_replay
(
times
-
1
,
session_id
)
class
CommandRecorder
(
metaclass
=
Singleton
):
class
CommandRecorder
(
object
):
batch_size
=
10
timeout
=
5
no
=
0
storage
=
None
_cache
=
[]
def
__new__
(
cls
,
*
args
,
**
kwargs
):
if
cls
.
_cache
:
return
cls
.
_cache
[
0
]
else
:
self
=
super
(
CommandRecorder
,
cls
)
.
__new__
(
cls
,
*
args
,
**
kwargs
)
cls
.
_cache
.
append
(
self
)
return
self
def
__init__
(
self
):
super
()
.
__init__
()
super
(
CommandRecorder
,
self
)
.
__init__
()
self
.
queue
=
MemoryQueue
()
self
.
stop_evt
=
threading
.
Event
()
self
.
push_to_server_async
()
...
...
coco/session.py
View file @
784af494
...
...
@@ -3,9 +3,13 @@
#
import
uuid
import
datetime
import
selectors
import
time
try
:
import
selectors
except
ImportError
:
import
selectors2
as
selectors
from
.utils
import
get_logger
,
wrap_with_warning
as
warn
,
\
wrap_with_line_feed
as
wr
,
ugettext
as
_
,
ignore_error
from
.service
import
app_service
...
...
coco/sftp.py
View file @
784af494
...
...
@@ -144,7 +144,7 @@ class SFTPServer(paramiko.SFTPServerInterface):
if
len
(
data
)
==
1
and
not
data
[
0
]:
return
request
host
,
*
path
=
data
host
,
path
=
data
[
0
],
data
[
1
:]
request
[
"host"
]
=
host
unique
,
su
=
self
.
host_has_unique_su
(
host
)
if
unique
:
...
...
coco/sshd.py
View file @
784af494
...
...
@@ -112,7 +112,7 @@ class SSHServer:
logger
.
info
(
"Request type `{}:{}`, dispatch to interactive mode"
.
format
(
kind
,
chan_type
))
try
:
InteractiveServer
(
client
)
.
interact
()
except
Exception
as
e
:
except
IndexError
as
e
:
logger
.
error
(
"Unexpected error occur: {}"
.
format
(
e
))
connection
=
Connection
.
get_connection
(
client
.
connection_id
)
connection
.
remove_client
(
client
.
id
)
...
...
coco/struct.py
View file @
784af494
...
...
@@ -21,7 +21,7 @@ class MultiQueueMixin:
self
.
put
(
i
)
class
MemoryQueue
(
MultiQueueMixin
,
queue
.
Queue
):
class
MemoryQueue
(
MultiQueueMixin
,
queue
.
Queue
,
object
):
pass
...
...
@@ -29,11 +29,11 @@ class SizedList(list):
def
__init__
(
self
,
maxsize
=
0
):
self
.
maxsize
=
maxsize
self
.
size
=
0
super
()
.
__init__
()
super
(
list
,
self
)
.
__init__
()
def
append
(
self
,
b
):
if
self
.
maxsize
==
0
or
self
.
size
<
self
.
maxsize
:
super
()
.
append
(
b
)
super
(
SizedList
,
self
)
.
append
(
b
)
self
.
size
+=
len
(
b
)
def
clean
(
self
):
...
...
coco/utils.py
View file @
784af494
...
...
@@ -12,7 +12,6 @@ from io import StringIO
from
binascii
import
hexlify
from
werkzeug.local
import
Local
,
LocalProxy
from
functools
import
partial
,
wraps
import
builtins
import
paramiko
import
pyte
...
...
@@ -431,11 +430,17 @@ def get_current_lang(attr):
def
_gettext
(
lang
):
import
builtins
if
lang
==
'en'
:
trans_en
.
install
()
else
:
trans_zh
.
install
()
return
builtins
.
__dict__
[
'_'
]
try
:
return
builtins
.
__dict__
[
'_'
]
except
KeyError
:
def
_f
(
x
):
return
x
return
_f
def
_find
(
attr
):
...
...
cocod
View file @
784af494
...
...
@@ -2,10 +2,10 @@
# -*- coding: utf-8 -*-
#
import
eventlet
from
eventlet.debug
import
hub_prevent_multiple_readers
eventlet
.
monkey_patch
()
hub_prevent_multiple_readers
(
False
)
#
import eventlet
#
from eventlet.debug import hub_prevent_multiple_readers
#
eventlet.monkey_patch()
#
hub_prevent_multiple_readers(False)
import
os
import
sys
...
...
@@ -15,7 +15,8 @@ import signal
dirs
=
(
'logs'
,
'keys'
)
for
d
in
dirs
:
os
.
makedirs
(
d
,
exist_ok
=
True
)
if
not
os
.
path
.
isdir
(
d
):
os
.
makedirs
(
d
)
from
coco
import
Coco
...
...
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