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
c6fc3dfe
Commit
c6fc3dfe
authored
Nov 10, 2016
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update terminal interval
parent
10aa8c40
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
60 additions
and
37 deletions
+60
-37
settings.py
apps/jumpserver/settings.py
+0
-1
api.py
apps/terminal/api.py
+30
-19
models.py
apps/terminal/models.py
+3
-2
serializers.py
apps/terminal/serializers.py
+6
-6
terminal_list.html
apps/terminal/templates/terminal/terminal_list.html
+14
-5
urls.py
apps/terminal/urls.py
+7
-4
No files found.
apps/jumpserver/settings.py
View file @
c6fc3dfe
...
...
@@ -284,7 +284,6 @@ BROKER_URL = 'redis://%(password)s%(host)s:%(port)s/3' % {
}
CELERY_RESULT_BACKEND
=
BROKER_URL
# Cache use redis
CACHES
=
{
'default'
:
{
...
...
apps/terminal/api.py
View file @
c6fc3dfe
# -*- coding: utf-8 -*-
#
from
django.core.cache
import
cache
from
django.conf
import
settings
from
rest_framework.generics
import
ListCreateAPIView
,
RetrieveUpdateDestroyAPIView
from
rest_framework.views
import
APIView
,
Response
from
rest_framework.viewsets
import
ModelViewSet
from
rest_framework.permissions
import
AllowAny
from
common.utils
import
signer
,
get_object_or_none
from
.models
import
Terminal
,
TerminalHeatbeat
from
.models
import
Terminal
,
HeatbeatFailedLog
from
.serializers
import
TerminalSerializer
,
TerminalHeatbeatSerializer
from
.hands
import
IsSuperUserOrTerminalUser
class
Terminal
CreateListApi
(
ListCreateAPIView
):
class
Terminal
ViewSet
(
ModelViewSet
):
queryset
=
Terminal
.
objects
.
all
()
serializer_class
=
TerminalSerializer
permission_classes
=
(
AllowAny
,)
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
def
create
(
self
,
request
,
*
args
,
**
kwargs
):
name
=
signer
.
unsign
(
request
.
data
.
get
(
'name'
,
''
))
if
name
:
terminal
=
get_object_or_none
(
Terminal
,
name
=
name
)
if
terminal
:
data
=
{
'data'
:
{
'name'
:
name
,
'id'
:
terminal
.
id
},
}
if
terminal
.
is_active
:
return
Response
(
data
=
{
'data'
:
{
'name'
:
name
,
'id'
:
terminal
.
id
},
'msg'
:
'Success'
},
status
=
200
)
data
[
'msg'
]
=
'Success'
return
Response
(
data
=
data
,
status
=
200
)
else
:
return
Response
(
data
=
{
'data'
:
{
'name'
:
name
,
'ip'
:
terminal
.
ip
},
'msg'
:
'Need admin active it'
},
status
=
203
)
data
[
'msg'
]
=
'Need admin active this terminal'
return
Response
(
data
=
data
,
status
=
203
)
else
:
ip
=
request
.
META
.
get
(
'X-Real-IP'
)
or
request
.
META
.
get
(
'REMOTE_ADDR'
)
terminal
=
Terminal
.
objects
.
create
(
name
=
name
,
ip
=
ip
)
return
Response
(
data
=
{
'data'
:
{
'name'
:
name
,
'ip'
:
terminal
.
ip
},
'msg'
:
'Need admin active it'
},
status
=
201
)
data
=
{
'data'
:
{
'name'
:
name
,
'id'
:
terminal
.
id
},
'msg'
:
'Need admin active this terminal'
,
}
return
Response
(
data
=
data
,
status
=
201
)
else
:
return
Response
(
data
=
{
'msg'
:
'Secrete key invalid'
},
status
=
401
)
class
TerminalHeatbeatApi
(
ListCreate
APIView
):
model
=
TerminalHeatbeat
serializer_class
=
TerminalHeatbeatSerializer
class
TerminalHeatbeatApi
(
APIView
):
# model = HeatbeatFailedLog
#
serializer_class = TerminalHeatbeatSerializer
permission_classes
=
(
IsSuperUserOrTerminalUser
,)
def
put
(
self
,
request
,
*
args
,
**
kwargs
):
terminal_id
=
request
.
user
.
id
cache
.
set
(
'terminal_heatbeat_
%
s'
%
terminal_id
,
settings
.
CONFIG
.
TERMINAL_HEATBEAT_INTERVAL
*
3
)
return
Response
({
'msg'
:
'Success'
})
class
TerminalApiDetailUpdateDetailApi
(
RetrieveUpdateDestroyAPIView
):
queryset
=
Terminal
.
objects
.
all
()
serializer_class
=
TerminalSerializer
permission_classes
=
(
IsSuperUserOrTerminalUser
,)
# class TerminalApiDetailUpdateDetailApi(RetrieveUpdateDestroyAPIView):
# queryset = Terminal.objects.all()
# serializer_class = TerminalSerializer
# permission_classes = (IsSuperUserOrTerminalUser,)
apps/terminal/models.py
View file @
c6fc3dfe
...
...
@@ -36,9 +36,10 @@ class Terminal(models.Model):
ordering
=
[
'is_active'
]
class
TerminalHeatbeat
(
models
.
Model
):
class
HeatbeatFailedLog
(
models
.
Model
):
"""Terminal heatbeat failed log"""
terminal
=
models
.
ForeignKey
(
Terminal
,
on_delete
=
models
.
CASCADE
)
date_created
=
models
.
DateTimeField
(
auto_now_add
=
True
)
class
Meta
:
db_table
=
'
terminal_heatbeat
'
db_table
=
'
heatbeat_failed_log
'
apps/terminal/serializers.py
View file @
c6fc3dfe
...
...
@@ -3,26 +3,26 @@
from
rest_framework
import
serializers
from
.models
import
Terminal
,
TerminalHeatbeat
from
.models
import
Terminal
,
HeatbeatFailedLog
from
.hands
import
ProxyLog
class
TerminalSerializer
(
serializers
.
ModelSerializer
):
proxy_
amount
=
serializers
.
SerializerMethodField
()
proxy_
online
=
serializers
.
SerializerMethodField
()
class
Meta
:
model
=
Terminal
fields
=
[
'id'
,
'name'
,
'ip'
,
'type'
,
'url'
,
'comment'
,
'is_active'
,
'
get_type_display'
,
'proxy_amount
'
]
fields
=
[
'id'
,
'name'
,
'ip'
,
'type'
,
'url'
,
'comment'
,
'
is_active'
,
'get_type_display'
,
'proxy_online
'
]
@staticmethod
def
get_proxy_
amount
(
obj
):
def
get_proxy_
online
(
obj
):
return
ProxyLog
.
objects
.
filter
(
terminal
=
obj
.
name
,
is_finished
=
False
)
.
count
()
class
TerminalHeatbeatSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
model
=
TerminalHeatbeat
model
=
HeatbeatFailedLog
fields
=
[
'terminal'
]
...
...
apps/terminal/templates/terminal/terminal_list.html
View file @
c6fc3dfe
...
...
@@ -27,8 +27,9 @@
<th
class=
"text-center"
>
{% trans 'Name' %}
</th>
<th
class=
"text-center"
>
{% trans 'IP' %}
</th>
<th
class=
"text-center"
>
{% trans 'Type' %}
</th>
<th
class=
"text-center"
>
{% trans 'proxy
_amount
' %}
</th>
<th
class=
"text-center"
>
{% trans 'proxy
online
' %}
</th>
<th
class=
"text-center"
>
{% trans 'Active' %}
</th>
<th
class=
"text-center"
>
{% trans 'Alive' %}
</th>
<th
class=
"text-center"
>
{% trans 'Action' %}
</th>
</tr>
</thead>
...
...
@@ -42,6 +43,7 @@
$
(
document
).
ready
(
function
(){
var
options
=
{
ele
:
$
(
'#terminal_list_table'
),
buttons
:
[],
columnDefs
:
[
{
targets
:
1
,
createdCell
:
function
(
td
,
cellData
,
rowData
)
{
var
detail_btn
=
'<a href="{% url "users:user-detail" pk=99991937 %}">'
+
cellData
+
'</a>'
;
...
...
@@ -54,7 +56,14 @@ $(document).ready(function(){
$
(
td
).
html
(
'<i class="fa fa-check text-navy"></i>'
)
}
}},
{
targets
:
6
,
createdCell
:
function
(
td
,
cellData
,
rowData
)
{
{
targets
:
6
,
createdCell
:
function
(
td
,
cellData
)
{
if
(
!
cellData
)
{
$
(
td
).
html
(
'<i class="fa fa-circle text-danger"></i>'
)
}
else
{
$
(
td
).
html
(
'<i class="fa fa-circle text-navy"></i>'
)
}
}},
{
targets
:
7
,
createdCell
:
function
(
td
,
cellData
,
rowData
)
{
console
.
log
(
rowData
.
name
);
var
update_btn
=
'<a href="{% url "terminal:terminal-update" pk=99991937 %}" class="btn btn-xs btn-info">{% trans "Update" %}</a>'
.
replace
(
'99991937'
,
cellData
);
...
...
@@ -64,9 +73,9 @@ $(document).ready(function(){
$
(
td
).
html
(
update_btn
+
delete_btn
)
}}
],
ajax_url
:
'{% url "terminal:
terminal-list-create-api
" %}'
,
ajax_url
:
'{% url "terminal:
api-terminal-list
" %}'
,
columns
:
[{
data
:
function
(){
return
""
}},
{
data
:
"name"
},
{
data
:
"ip"
},
{
data
:
"get_type_display"
},
{
data
:
"proxy_
amount"
},
{
data
:
"is_active"
},
{
data
:
"id"
}],
{
data
:
"proxy_
online"
},
{
data
:
"is_active"
},
{
data
:
'is_active'
},
{
data
:
"id"
}],
op_html
:
$
(
'#actions'
).
html
()
};
jumpserver
.
initDataTable
(
options
);
...
...
@@ -74,7 +83,7 @@ $(document).ready(function(){
var
$this
=
$
(
this
);
var
uid
=
$this
.
data
(
'uid'
);
var
name
=
$
(
this
).
data
(
'name'
);
var
the_url
=
'{% url "terminal:
terminal-detail-update-delete-api
" pk=99991937 %}'
.
replace
(
'99991937'
,
uid
);
var
the_url
=
'{% url "terminal:
api-terminal-detail
" pk=99991937 %}'
.
replace
(
'99991937'
,
uid
);
objectDelete
(
$this
,
name
,
the_url
)
})
</script>
...
...
apps/terminal/urls.py
View file @
c6fc3dfe
...
...
@@ -3,6 +3,7 @@
#
from
django.conf.urls
import
url
from
rest_framework
import
routers
import
views
import
api
...
...
@@ -14,9 +15,11 @@ urlpatterns = [
url
(
r'^terminal/(?P<pk>\d+)/update$'
,
views
.
TerminalUpdateView
.
as_view
(),
name
=
'terminal-update'
),
]
router
=
routers
.
DefaultRouter
()
router
.
register
(
r'v1/terminal'
,
api
.
TerminalViewSet
,
'api-terminal'
)
urlpatterns
+=
[
url
(
r'^v1/terminal/$'
,
api
.
TerminalCreateListApi
.
as_view
(),
name
=
'terminal-list-create-api'
),
url
(
r'^v1/terminal/(?P<pk>\d+)/$'
,
api
.
TerminalApiDetailUpdateDetailApi
.
as_view
(),
name
=
'terminal-detail-update-delete-api'
),
url
(
r'^v1/terminal-heatbeat/$'
,
api
.
TerminalHeatbeatApi
.
as_view
(),
name
=
'terminal-heatbeat-api'
),
url
(
r'^v1/terminal/heatbeat/$'
,
api
.
TerminalHeatbeatApi
.
as_view
(),
name
=
'terminal-heatbeat-api'
),
]
urlpatterns
+=
router
.
urls
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