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
6a623a6d
Commit
6a623a6d
authored
Oct 20, 2017
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] Change select to selector
parent
6f072d57
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
31 additions
and
11 deletions
+31
-11
app.py
coco/app.py
+11
-1
forward.py
coco/forward.py
+2
-2
interactive.py
coco/interactive.py
+9
-0
models.py
coco/models.py
+1
-1
session.py
coco/session.py
+1
-3
sshd.py
coco/sshd.py
+2
-3
manage.py
manage.py
+5
-1
No files found.
coco/app.py
View file @
6a623a6d
...
...
@@ -37,7 +37,7 @@ class Coco:
def
__init__
(
self
,
name
=
None
,
root_path
=
None
):
self
.
config
=
self
.
config_class
(
BASE_DIR
,
defaults
=
self
.
default_config
)
self
.
sessions
=
[]
self
.
c
onnection
s
=
[]
self
.
c
lient
s
=
[]
self
.
ws
=
None
self
.
root_path
=
root_path
self
.
name
=
name
...
...
@@ -96,6 +96,16 @@ class Coco:
print
(
"Grace shutdown the server"
)
self
.
sshd
.
shutdown
()
def
add_client
(
self
,
client
):
self
.
clients
.
append
(
client
)
print
(
"
%
s add client, now
%
d s"
%
(
self
.
name
,
len
(
self
.
clients
)))
def
remove_client
(
self
,
client
):
self
.
clients
.
remove
(
client
)
client
.
send
(
"Closed by server"
)
client
.
close
()
print
(
"
%
s remove client, now
%
d s"
%
(
self
.
name
,
len
(
self
.
clients
)))
def
monitor_session
(
self
):
pass
coco/forward.py
View file @
6a623a6d
#coding: utf-8
# coding: utf-8
import
socket
import
paramiko
...
...
@@ -34,7 +35,6 @@ class ProxyServer:
pass
def
get_server_conn
(
self
,
asset
,
system_user
):
self
.
ssh
=
ssh
=
paramiko
.
SSHClient
()
ssh
.
set_missing_host_key_policy
(
paramiko
.
AutoAddPolicy
())
try
:
...
...
coco/interactive.py
View file @
6a623a6d
...
...
@@ -47,6 +47,8 @@ class InteractiveServer:
r
,
w
,
x
=
select
.
select
([
self
.
client
],
[],
[])
if
self
.
client
in
r
:
data
=
self
.
client
.
recv
(
10
)
if
len
(
data
)
==
0
:
self
.
app
.
remove_client
(
self
.
client
)
# Client input backspace
if
data
in
char
.
BACKSPACE_CHAR
:
# If input words less than 0, should send 'BELL'
...
...
@@ -80,6 +82,13 @@ class InteractiveServer:
input_data
.
append
(
data
)
def
dispatch
(
self
,
opt
):
print
(
opt
)
if
opt
in
[
'q'
,
'Q'
]:
self
.
app
.
remove_client
(
self
.
client
)
return
else
:
self
.
client
.
send
(
"hello"
)
asset
=
Asset
(
id
=
1
,
hostname
=
"123.57.183.135"
,
ip
=
"123.57.183.135"
,
port
=
8022
)
system_user
=
SystemUser
(
id
=
2
,
username
=
"web"
,
password
=
"redhat123"
,
name
=
"web"
)
self
.
connect
(
asset
,
system_user
)
...
...
coco/models.py
View file @
6a623a6d
...
...
@@ -49,7 +49,7 @@ class SystemUser(Decoder):
name
=
""
username
=
""
password
=
""
private_key
=
""
private_key
=
None
def
__str__
(
self
):
return
self
.
name
...
...
coco/session.py
View file @
6a623a6d
...
...
@@ -51,7 +51,7 @@ class Session:
while
self
.
running
:
try
:
r
,
w
,
x
=
select
.
select
([
self
.
client
+
self
.
server
]
+
self
.
watchers
+
self
.
sharers
,
[],
[])
+
self
.
sharers
,
[],
[])
for
sock
in
r
:
if
sock
==
self
.
server
:
...
...
@@ -67,8 +67,6 @@ class Session:
watcher
.
send
(
"
%
s close the session"
%
self
.
client
)
self
.
close
()
self
.
server
.
send
(
data
)
elif
sock
in
self
.
watchers
:
sock
.
send
(
"WARN: Your didn't have the write permission
\r\n
"
)
elif
sock
in
self
.
sharers
:
data
=
sock
.
recv
(
BUF_SIZE
)
if
len
(
data
)
==
0
:
...
...
coco/sshd.py
View file @
6a623a6d
...
...
@@ -61,13 +61,11 @@ class SSHServer:
try
:
sock
,
addr
=
self
.
sock
.
accept
()
logger
.
info
(
"Get ssh request from
%
s:
%
s"
%
(
addr
[
0
],
addr
[
1
]))
if
len
(
self
.
app
.
c
onnection
s
)
>=
max_conn_num
:
if
len
(
self
.
app
.
c
lient
s
)
>=
max_conn_num
:
sock
.
close
()
logger
.
warning
(
"Arrive max connection number
%
s, "
"reject new request
%
s:
%
s"
%
(
max_conn_num
,
addr
[
0
],
addr
[
1
]))
else
:
self
.
app
.
connections
.
append
((
sock
,
addr
))
thread
=
threading
.
Thread
(
target
=
self
.
handle
,
args
=
(
sock
,
addr
))
thread
.
daemon
=
True
thread
.
start
()
...
...
@@ -101,6 +99,7 @@ class SSHServer:
sys
.
exit
(
2
)
client
=
Client
(
chan
,
addr
,
request
.
user
)
self
.
app
.
add_client
(
client
)
self
.
dispatch
(
request
,
client
)
def
dispatch
(
self
,
request
,
client
):
...
...
manage.py
View file @
6a623a6d
...
...
@@ -16,7 +16,11 @@ except:
coco
=
Coco
()
coco
.
config
.
from_object
(
conf
)
print
(
coco
.
root_path
)
# Todo:
# 0. argparser
# 1. register application user
# 2. backup record file
# 3. xxx
if
__name__
==
'__main__'
:
coco
.
run_forever
()
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