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
3d705dbe
Commit
3d705dbe
authored
Dec 26, 2017
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Bugfix] 修复一些bug
parent
22b7b84a
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
59 additions
and
40 deletions
+59
-40
forms.py
apps/assets/forms.py
+3
-0
user_asset_list.html
apps/assets/templates/assets/user_asset_list.html
+9
-2
views_urls.py
apps/terminal/urls/views_urls.py
+1
-0
utils.py
apps/terminal/utils.py
+0
-2
terminal.py
apps/terminal/views/terminal.py
+8
-2
run_server.py
run_server.py
+38
-34
No files found.
apps/assets/forms.py
View file @
3d705dbe
...
...
@@ -224,11 +224,14 @@ class SystemUserForm(forms.ModelForm):
password
=
self
.
cleaned_data
.
get
(
'password'
,
None
)
private_key_file
=
self
.
cleaned_data
.
get
(
'private_key_file'
)
auto_generate_key
=
self
.
cleaned_data
.
get
(
'auto_generate_key'
)
private_key
=
None
public_key
=
None
if
auto_generate_key
:
logger
.
info
(
'Auto set system user auth'
)
system_user
.
auto_gen_auth
()
else
:
if
private_key_file
:
private_key
=
private_key_file
.
read
()
.
strip
()
.
decode
(
'utf-8'
)
public_key
=
ssh_pubkey_gen
(
private_key
=
private_key
)
system_user
.
set_auth
(
password
=
password
,
private_key
=
private_key
,
public_key
=
public_key
)
...
...
apps/assets/templates/assets/user_asset_list.html
View file @
3d705dbe
...
...
@@ -34,6 +34,7 @@
<th
class=
"text-center"
>
{% trans 'Hardware' %}
</th>
<th
class=
"text-center"
>
{% trans 'Active' %}
</th>
<th
class=
"text-center"
>
{% trans 'Connective' %}
</th>
<th
class=
"text-center"
>
{% trans 'Action' %}
</th>
</tr>
</thead>
<tbody>
...
...
@@ -70,12 +71,18 @@ function initTable() {
}
else
{
$
(
td
).
html
(
'<i class="fa fa-circle text-navy"></i>'
)
}
}},
{
targets
:
9
,
createdCell
:
function
(
td
,
cellData
,
rowData
)
{
var
conn_btn
=
'<a href="{% url "terminal:web-terminal" %}?id={{ DEFAULT_PK }}" class="btn btn-xs btn-info">{% trans "Connect" %}</a>'
.
replace
(
"{{ DEFAULT_PK }}"
,
cellData
);
$
(
td
).
html
(
conn_btn
)
}}
],
ajax_url
:
'{% url "api-assets:asset-list" %}'
,
columns
:
[{
data
:
"id"
},
{
data
:
"hostname"
},
{
data
:
"ip"
},
{
data
:
"port"
},
columns
:
[
{
data
:
"id"
},
{
data
:
"hostname"
},
{
data
:
"ip"
},
{
data
:
"port"
},
{
data
:
"get_type_display"
},
{
data
:
"get_env_display"
},
{
data
:
"hardware_info"
},
{
data
:
"is_active"
},
{
data
:
"is_connective"
}],
{
data
:
"is_active"
},
{
data
:
"is_connective"
},
{
data
:
"id"
}
],
op_html
:
$
(
'#actions'
).
html
()
};
return
jumpserver
.
initDataTable
(
options
);
...
...
apps/terminal/urls/views_urls.py
View file @
3d705dbe
...
...
@@ -15,6 +15,7 @@ urlpatterns = [
url
(
r'^terminal/(?P<pk>[0-9a-zA-Z\-]{36})/connect/$'
,
views
.
TerminalConnectView
.
as_view
(),
name
=
'terminal-connect'
),
url
(
r'^terminal/(?P<pk>[0-9a-zA-Z\-]{36})/update/$'
,
views
.
TerminalUpdateView
.
as_view
(),
name
=
'terminal-update'
),
url
(
r'^(?P<pk>[0-9a-zA-Z\-]{36})/accept/$'
,
views
.
TerminalAcceptView
.
as_view
(),
name
=
'terminal-accept'
),
url
(
r'^web-terminal/$'
,
views
.
WebTerminalView
.
as_view
(),
name
=
'web-terminal'
),
# Session view
url
(
r'^session-online/$'
,
views
.
SessionOnlineListView
.
as_view
(),
name
=
'session-online-list'
),
...
...
apps/terminal/utils.py
View file @
3d705dbe
...
...
@@ -18,8 +18,6 @@ def get_session_system_user_list():
return
set
(
list
(
Session
.
objects
.
values_list
(
'system_user'
,
flat
=
True
)))
def
get_user_list_from_cache
():
return
cache
.
get
(
USERS_CACHE_KEY
)
...
...
apps/terminal/views/terminal.py
View file @
3d705dbe
# ~*~ coding: utf-8 ~*~
#
from
django.views.generic
import
ListView
,
UpdateView
,
DeleteView
,
\
DetailView
,
Template
View
DetailView
,
View
from
django.contrib.auth.mixins
import
LoginRequiredMixin
from
django.utils.translation
import
ugettext
as
_
from
django.shortcuts
import
redirect
from
django.urls
import
reverse_lazy
,
reverse
from
common.mixins
import
JSONResponseMixin
...
...
@@ -16,6 +16,7 @@ from ..hands import AdminUserRequiredMixin
__all__
=
[
"TerminalListView"
,
"TerminalUpdateView"
,
"TerminalDetailView"
,
"TerminalDeleteView"
,
"TerminalConnectView"
,
"TerminalAcceptView"
,
"WebTerminalView"
,
]
...
...
@@ -115,3 +116,8 @@ class TerminalConnectView(LoginRequiredMixin, DetailView):
kwargs
.
update
(
context
)
return
super
(
TerminalConnectView
,
self
)
.
get_context_data
(
**
kwargs
)
class
WebTerminalView
(
LoginRequiredMixin
,
View
):
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
return
redirect
(
'/luna/?'
+
request
.
GET
.
urlencode
())
run_server.py
View file @
3d705dbe
...
...
@@ -6,6 +6,7 @@ import threading
import
time
import
argparse
import
platform
import
sys
from
apps
import
__version__
...
...
@@ -27,6 +28,7 @@ EXIT_EVENT = threading.Event()
EXIT_MSGS
=
[]
try
:
os
.
makedirs
(
os
.
path
.
join
(
BASE_DIR
,
"data"
,
"static"
))
os
.
makedirs
(
os
.
path
.
join
(
BASE_DIR
,
"data"
,
"media"
))
...
...
@@ -54,9 +56,8 @@ def start_gunicorn():
cmd
=
"gunicorn jumpserver.wsgi -b {}:{} -w {}"
.
format
(
HTTP_HOST
,
HTTP_PORT
,
WORKERS
)
if
DEBUG
:
cmd
+=
" --reload"
subprocess
.
call
(
cmd
,
shell
=
True
)
EXIT_MSGS
.
append
(
"Gunicorn start failed"
)
EXIT_EVENT
.
set
()
p
=
subprocess
.
Popen
(
cmd
,
shell
=
True
,
stdout
=
sys
.
stdout
,
stderr
=
sys
.
stderr
)
return
p
def
start_celery
():
...
...
@@ -68,16 +69,15 @@ def start_celery():
if
platform
.
platform
()
.
startswith
(
"Linux"
):
cmd
=
"""
id jumpserver || useradd -s /sbin/nologin jumpserver;
su jumpserver -c 'celery -A common worker -l {}'
su jumpserver -c 'celery -A common worker -l {}'
;
"""
.
format
(
LOG_LEVEL
.
lower
())
else
:
cmd
=
"""
export C_FORCE_ROOT=1;celery -A common worker -l {}
'
export C_FORCE_ROOT=1;celery -A common worker -l {}
"""
.
format
(
LOG_LEVEL
.
lower
())
subprocess
.
call
(
cmd
,
shell
=
True
)
EXIT_MSGS
.
append
(
"Celery start failed"
)
EXIT_EVENT
.
set
()
p
=
subprocess
.
Popen
(
cmd
,
shell
=
True
,
stdout
=
sys
.
stdout
,
stderr
=
sys
.
stderr
)
return
p
def
start_beat
():
...
...
@@ -86,40 +86,44 @@ def start_beat():
os
.
environ
.
setdefault
(
'PYTHONOPTIMIZE'
,
'1'
)
os
.
environ
.
setdefault
(
'C_FORCE_ROOT'
,
'1'
)
scheduler
=
"django_celery_beat.schedulers:DatabaseScheduler"
cmd
=
'celery -A common beat -l {} --scheduler {} --max-interval 5 '
.
format
(
LOG_LEVEL
,
scheduler
)
subprocess
.
call
(
cmd
,
shell
=
True
)
EXIT_MSGS
.
append
(
"Beat start failed"
)
EXIT_EVENT
.
set
()
cmd
=
'celery -A common beat -l {} --scheduler {} --max-interval 60 '
.
format
(
LOG_LEVEL
,
scheduler
)
p
=
subprocess
.
Popen
(
cmd
,
shell
=
True
,
stdout
=
sys
.
stdout
,
stderr
=
sys
.
stderr
)
return
p
def
start_service
(
services
):
make_migrations
()
print
(
time
.
ctime
())
print
(
'Jumpserver version {}, more see https://www.jumpserver.org'
.
format
(
__version__
))
print
(
'Quit the server with CONTROL-C.'
)
threads
=
[]
if
'gunicorn'
in
args
.
services
:
threads
.
append
(
threading
.
Thread
(
target
=
start_gunicorn
,
args
=
()))
if
'celery'
in
args
.
services
:
threads
.
append
(
threading
.
Thread
(
target
=
start_celery
,
args
=
()))
if
'beat'
in
args
.
services
:
threads
.
append
(
threading
.
Thread
(
target
=
start_beat
,
args
=
()))
if
'all'
in
args
.
services
:
_threads
=
[]
for
func
in
(
start_gunicorn
,
start_celery
,
start_beat
):
t
=
threading
.
Thread
(
target
=
func
,
args
=
())
_threads
.
append
(
t
)
threads
=
_threads
for
t
in
threads
:
t
.
start
()
if
EXIT_EVENT
.
wait
():
print
(
"
\n\n
"
+
"####"
*
30
)
print
(
"
\n
"
.
join
(
EXIT_MSGS
))
processes
=
{}
services_all
=
{
"gunicorn"
:
start_gunicorn
,
"celery"
:
start_celery
,
"beat"
:
start_beat
}
if
'all'
in
services
:
for
name
,
func
in
services_all
.
items
():
processes
[
name
]
=
func
()
else
:
for
name
in
services
:
func
=
services_all
.
get
(
name
)
processes
[
name
]
=
func
()
stop_event
=
threading
.
Event
()
while
not
stop_event
.
is_set
():
for
name
,
proc
in
processes
.
items
():
if
proc
.
poll
()
is
not
None
:
print
(
"
\n\n
"
+
"####"
*
10
+
" ERROR OCCUR "
+
"####"
*
10
)
print
(
"Start service {} [FAILED]"
.
format
(
name
))
for
_
,
p
in
processes
.
items
():
p
.
terminate
()
stop_event
.
set
()
print
(
"Exited"
.
format
(
name
))
break
time
.
sleep
(
5
)
if
__name__
==
'__main__'
:
...
...
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