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
6a510dad
Commit
6a510dad
authored
Oct 24, 2016
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update some bug
parent
6b161d59
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
66 additions
and
37 deletions
+66
-37
asset_list.html
apps/assets/templates/assets/asset_list.html
+1
-1
views.py
apps/assets/views.py
+5
-5
jumpserver.js
apps/static/js/jumpserver.js
+27
-18
api.py
apps/terminal/api.py
+9
-4
terminal_list.html
apps/terminal/templates/terminal/terminal_list.html
+13
-7
urls.py
apps/terminal/urls.py
+2
-0
views.py
apps/terminal/views.py
+8
-1
backends.py
apps/users/backends.py
+1
-1
No files found.
apps/assets/templates/assets/asset_list.html
View file @
6a510dad
...
@@ -146,7 +146,7 @@
...
@@ -146,7 +146,7 @@
"aoColumnDefs"
:
[
{
"bSortable"
:
false
,
"aTargets"
:
[
0
]
}],
"aoColumnDefs"
:
[
{
"bSortable"
:
false
,
"aTargets"
:
[
0
]
}],
"bAutoWidth"
:
false
,
"bAutoWidth"
:
false
,
"language"
:
{
"language"
:
{
"url"
:
"/static/js/plugins/dataTables/i18n/zh-hans.json"
"url"
:
"/static/js/plugins/dataTables/i18n/zh-hans.json"
},
},
columns
:
[
columns
:
[
{
data
:
"checkbox"
},
{
data
:
"checkbox"
},
...
...
apps/assets/views.py
View file @
6a510dad
...
@@ -74,8 +74,6 @@ class AssetCreateView(AdminUserRequiredMixin,CreateAssetTagsMiXin,CreateView):
...
@@ -74,8 +74,6 @@ class AssetCreateView(AdminUserRequiredMixin,CreateAssetTagsMiXin,CreateView):
return
super
(
AssetCreateView
,
self
)
.
get_context_data
(
**
kwargs
)
return
super
(
AssetCreateView
,
self
)
.
get_context_data
(
**
kwargs
)
class
AssetUpdateView
(
AdminUserRequiredMixin
,
UpdateAssetTagsMiXin
,
UpdateView
):
class
AssetUpdateView
(
AdminUserRequiredMixin
,
UpdateAssetTagsMiXin
,
UpdateView
):
model
=
Asset
model
=
Asset
form_class
=
AssetCreateForm
form_class
=
AssetCreateForm
...
@@ -118,13 +116,13 @@ class AssetDetailView(DetailView):
...
@@ -118,13 +116,13 @@ class AssetDetailView(DetailView):
kwargs
.
update
(
context
)
kwargs
.
update
(
context
)
return
super
(
AssetDetailView
,
self
)
.
get_context_data
(
**
kwargs
)
return
super
(
AssetDetailView
,
self
)
.
get_context_data
(
**
kwargs
)
class
AssetModalListView
(
AdminUserRequiredMixin
,
ListView
):
class
AssetModalListView
(
AdminUserRequiredMixin
,
ListView
):
paginate_by
=
settings
.
CONFIG
.
DISPLAY_PER_PAGE
paginate_by
=
settings
.
CONFIG
.
DISPLAY_PER_PAGE
model
=
Asset
model
=
Asset
context_object_name
=
'asset_modal_list'
context_object_name
=
'asset_modal_list'
template_name
=
'assets/asset_modal_list.html'
template_name
=
'assets/asset_modal_list.html'
def
get_context_data
(
self
,
**
kwargs
):
def
get_context_data
(
self
,
**
kwargs
):
group_id
=
self
.
request
.
GET
.
get
(
'group_id'
)
group_id
=
self
.
request
.
GET
.
get
(
'group_id'
)
tag_id
=
self
.
request
.
GET
.
get
(
'tag_id'
)
tag_id
=
self
.
request
.
GET
.
get
(
'tag_id'
)
...
@@ -142,6 +140,7 @@ class AssetModalListView(AdminUserRequiredMixin, ListView):
...
@@ -142,6 +140,7 @@ class AssetModalListView(AdminUserRequiredMixin, ListView):
kwargs
.
update
(
context
)
kwargs
.
update
(
context
)
return
super
(
AssetModalListView
,
self
)
.
get_context_data
(
**
kwargs
)
return
super
(
AssetModalListView
,
self
)
.
get_context_data
(
**
kwargs
)
class
AssetGroupCreateView
(
AdminUserRequiredMixin
,
CreateView
):
class
AssetGroupCreateView
(
AdminUserRequiredMixin
,
CreateView
):
model
=
AssetGroup
model
=
AssetGroup
form_class
=
AssetGroupForm
form_class
=
AssetGroupForm
...
@@ -160,7 +159,6 @@ class AssetGroupCreateView(AdminUserRequiredMixin, CreateView):
...
@@ -160,7 +159,6 @@ class AssetGroupCreateView(AdminUserRequiredMixin, CreateView):
kwargs
.
update
(
context
)
kwargs
.
update
(
context
)
return
super
(
AssetGroupCreateView
,
self
)
.
get_context_data
(
**
kwargs
)
return
super
(
AssetGroupCreateView
,
self
)
.
get_context_data
(
**
kwargs
)
def
form_valid
(
self
,
form
):
def
form_valid
(
self
,
form
):
asset_group
=
form
.
save
()
asset_group
=
form
.
save
()
assets_id_list
=
self
.
request
.
POST
.
getlist
(
'assets'
,
[])
assets_id_list
=
self
.
request
.
POST
.
getlist
(
'assets'
,
[])
...
@@ -170,6 +168,7 @@ class AssetGroupCreateView(AdminUserRequiredMixin, CreateView):
...
@@ -170,6 +168,7 @@ class AssetGroupCreateView(AdminUserRequiredMixin, CreateView):
asset_group
.
save
()
asset_group
.
save
()
return
super
(
AssetGroupCreateView
,
self
)
.
form_valid
(
form
)
return
super
(
AssetGroupCreateView
,
self
)
.
form_valid
(
form
)
class
AssetGroupListView
(
AdminUserRequiredMixin
,
ListView
):
class
AssetGroupListView
(
AdminUserRequiredMixin
,
ListView
):
model
=
AssetGroup
model
=
AssetGroup
paginate_by
=
settings
.
CONFIG
.
DISPLAY_PER_PAGE
paginate_by
=
settings
.
CONFIG
.
DISPLAY_PER_PAGE
...
@@ -218,6 +217,7 @@ class AssetGroupDetailView(SingleObjectMixin, AdminUserRequiredMixin, ListView):
...
@@ -218,6 +217,7 @@ class AssetGroupDetailView(SingleObjectMixin, AdminUserRequiredMixin, ListView):
kwargs
.
update
(
context
)
kwargs
.
update
(
context
)
return
super
(
AssetGroupDetailView
,
self
)
.
get_context_data
(
**
kwargs
)
return
super
(
AssetGroupDetailView
,
self
)
.
get_context_data
(
**
kwargs
)
class
AssetGroupUpdateView
(
AdminUserRequiredMixin
,
UpdateView
):
class
AssetGroupUpdateView
(
AdminUserRequiredMixin
,
UpdateView
):
model
=
AssetGroup
model
=
AssetGroup
form_class
=
AssetGroupForm
form_class
=
AssetGroupForm
...
@@ -296,6 +296,7 @@ class IDCCreateView(AdminUserRequiredMixin, CreateView):
...
@@ -296,6 +296,7 @@ class IDCCreateView(AdminUserRequiredMixin, CreateView):
# IDC_add_success_next(user)
# IDC_add_success_next(user)
return
super
(
IDCCreateView
,
self
)
.
form_valid
(
form
)
return
super
(
IDCCreateView
,
self
)
.
form_valid
(
form
)
class
IDCUpdateView
(
AdminUserRequiredMixin
,
UpdateView
):
class
IDCUpdateView
(
AdminUserRequiredMixin
,
UpdateView
):
model
=
IDC
model
=
IDC
form_class
=
IDCForm
form_class
=
IDCForm
...
@@ -327,7 +328,6 @@ class IDCDeleteView(AdminUserRequiredMixin, DeleteView):
...
@@ -327,7 +328,6 @@ class IDCDeleteView(AdminUserRequiredMixin, DeleteView):
success_url
=
reverse_lazy
(
'assets:idc-list'
)
success_url
=
reverse_lazy
(
'assets:idc-list'
)
class
AdminUserListView
(
AdminUserRequiredMixin
,
ListView
):
class
AdminUserListView
(
AdminUserRequiredMixin
,
ListView
):
model
=
AdminUser
model
=
AdminUser
paginate_by
=
settings
.
CONFIG
.
DISPLAY_PER_PAGE
paginate_by
=
settings
.
CONFIG
.
DISPLAY_PER_PAGE
...
...
apps/static/js/jumpserver.js
View file @
6a510dad
...
@@ -197,7 +197,7 @@ function APIUpdateAttr(props) {
...
@@ -197,7 +197,7 @@ function APIUpdateAttr(props) {
type
:
props
.
method
||
"PATCH"
,
type
:
props
.
method
||
"PATCH"
,
data
:
props
.
body
,
data
:
props
.
body
,
contentType
:
props
.
content_type
||
"application/json; charset=utf-8"
,
contentType
:
props
.
content_type
||
"application/json; charset=utf-8"
,
dataType
:
props
.
data_type
||
"json"
,
dataType
:
props
.
data_type
||
"json"
}).
done
(
function
(
data
,
textStatue
,
jqXHR
)
{
}).
done
(
function
(
data
,
textStatue
,
jqXHR
)
{
if
(
typeof
props
.
success
===
'function'
)
{
if
(
typeof
props
.
success
===
'function'
)
{
return
props
.
success
(
data
);
return
props
.
success
(
data
);
...
@@ -215,28 +215,37 @@ function APIUpdateAttr(props) {
...
@@ -215,28 +215,37 @@ function APIUpdateAttr(props) {
}
}
// Sweet Alert for Delete
// Sweet Alert for Delete
function
objectDelete
(
obj
,
name
,
url
){
function
objectDelete
(
obj
,
name
,
url
)
{
var
$this
=
$
(
this
);
function
doDelete
()
{
var
uid
=
$this
.
data
(
'uid'
);
var
body
=
{};
var
success
=
function
()
{
swal
(
'Deleted!'
,
"[ "
+
name
+
"]"
+
" has been deleted "
,
"success"
);
$
(
obj
).
parent
().
parent
().
remove
();
};
var
fail
=
function
()
{
swal
(
"Failed"
,
"Delete"
+
"[ "
+
name
+
" ]"
+
"failed"
,
"error"
);
};
APIUpdateAttr
({
url
:
url
,
body
:
JSON
.
stringify
(
body
),
method
:
'DELETE'
,
success
:
success
,
error
:
fail
});
}
swal
({
swal
({
title
:
'Are you sure delete ?'
,
title
:
'Are you sure delete ?'
,
text
:
"
【"
+
name
+
"】
"
,
text
:
"
["
+
name
+
"]
"
,
type
:
"warning"
,
type
:
"warning"
,
showCancelButton
:
true
,
showCancelButton
:
true
,
cancelButtonText
:
'Cancel'
,
cancelButtonText
:
'Cancel'
,
confirmButtonColor
:
"#DD6B55"
,
confirmButtonColor
:
"#DD6B55"
,
confirmButtonText
:
'
Yes, delete it!
'
,
confirmButtonText
:
'
Confirm
'
,
closeOnConfirm
:
false
closeOnConfirm
:
false
},
function
()
{
},
function
()
{
$
.
ajax
({
doDelete
()
type
:
"post"
,
url
:
url
,
data
:
{
},
dataType
:
"text"
,
success
:
function
(
data
)
{
swal
(
'Deleted!'
,
"【"
+
name
+
"】"
+
"has been deleted."
,
"success"
);
$
(
obj
).
parent
().
parent
().
remove
();
}
});
});
});
}
}
...
@@ -279,7 +288,7 @@ jumpserver.initDataTable = function (options) {
...
@@ -279,7 +288,7 @@ jumpserver.initDataTable = function (options) {
$
(
td
).
html
(
'<div class="checkbox checkbox-default"><input type="checkbox" class="ipt_check"><label></label></div>'
);
$
(
td
).
html
(
'<div class="checkbox checkbox-default"><input type="checkbox" class="ipt_check"><label></label></div>'
);
}
}
},
},
{
className
:
'text-center'
,
targets
:
'_all'
}
,
{
className
:
'text-center'
,
targets
:
'_all'
}
];
];
columnDefs
=
options
.
columnDefs
?
options
.
columnDefs
.
concat
(
columnDefs
)
:
columnDefs
;
columnDefs
=
options
.
columnDefs
?
options
.
columnDefs
.
concat
(
columnDefs
)
:
columnDefs
;
var
table
=
ele
.
DataTable
({
var
table
=
ele
.
DataTable
({
...
@@ -342,6 +351,6 @@ jumpserver.initDataTable = function (options) {
...
@@ -342,6 +351,6 @@ jumpserver.initDataTable = function (options) {
jumpserver
.
checked
=
false
;
jumpserver
.
checked
=
false
;
table
.
rows
().
deselect
();
table
.
rows
().
deselect
();
}
}
})
})
;
return
table
;
return
table
;
}
}
;
apps/terminal/api.py
View file @
6a510dad
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
#
#
from
rest_framework.generics
import
ListCreateAPIView
,
Create
APIView
from
rest_framework.generics
import
ListCreateAPIView
,
RetrieveUpdateDestroy
APIView
from
rest_framework.views
import
APIView
,
Response
from
rest_framework.views
import
APIView
,
Response
from
rest_framework.permissions
import
AllowAny
from
rest_framework.permissions
import
AllowAny
...
@@ -18,7 +18,6 @@ class TerminalCreateListApi(ListCreateAPIView):
...
@@ -18,7 +18,6 @@ class TerminalCreateListApi(ListCreateAPIView):
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
name
=
unsign
(
request
.
data
.
get
(
'name'
,
''
))
name
=
unsign
(
request
.
data
.
get
(
'name'
,
''
))
print
(
name
)
if
name
:
if
name
:
terminal
=
get_object_or_none
(
Terminal
,
name
=
name
)
terminal
=
get_object_or_none
(
Terminal
,
name
=
name
)
if
terminal
:
if
terminal
:
...
@@ -36,12 +35,18 @@ class TerminalCreateListApi(ListCreateAPIView):
...
@@ -36,12 +35,18 @@ class TerminalCreateListApi(ListCreateAPIView):
terminal
=
Terminal
.
objects
.
create
(
name
=
name
,
ip
=
ip
)
terminal
=
Terminal
.
objects
.
create
(
name
=
name
,
ip
=
ip
)
return
Response
(
data
=
{
'data'
:
{
'name'
:
name
,
'ip'
:
terminal
.
ip
},
return
Response
(
data
=
{
'data'
:
{
'name'
:
name
,
'ip'
:
terminal
.
ip
},
'msg'
:
'Need admin active it'
},
'msg'
:
'Need admin active it'
},
status
=
20
4
)
status
=
20
1
)
else
:
else
:
return
Response
(
data
=
{
'msg'
:
'Secrete key invalid'
},
status
=
401
)
return
Response
(
data
=
{
'msg'
:
'Secrete key invalid'
},
status
=
401
)
class
TerminalHeatbeatApi
(
CreateAPIView
):
class
TerminalHeatbeatApi
(
List
CreateAPIView
):
model
=
TerminalHeatbeat
model
=
TerminalHeatbeat
serializer_class
=
TerminalHeatbeatSerializer
serializer_class
=
TerminalHeatbeatSerializer
permission_classes
=
(
IsSuperUserOrTerminalUser
,)
permission_classes
=
(
IsSuperUserOrTerminalUser
,)
class
TerminalApiDetailUpdateDetailApi
(
RetrieveUpdateDestroyAPIView
):
queryset
=
Terminal
.
objects
.
all
()
serializer_class
=
TerminalSerializer
permission_classes
=
(
IsSuperUserOrTerminalUser
,)
apps/terminal/templates/terminal/terminal_list.html
View file @
6a510dad
...
@@ -47,10 +47,6 @@ $(document).ready(function(){
...
@@ -47,10 +47,6 @@ $(document).ready(function(){
var
detail_btn
=
'<a href="{% url "users:user-detail" pk=99991937 %}">'
+
cellData
+
'</a>'
;
var
detail_btn
=
'<a href="{% url "users:user-detail" pk=99991937 %}">'
+
cellData
+
'</a>'
;
$
(
td
).
html
(
detail_btn
.
replace
(
'99991937'
,
rowData
.
id
));
$
(
td
).
html
(
detail_btn
.
replace
(
'99991937'
,
rowData
.
id
));
}},
}},
{
targets
:
4
,
createdCell
:
function
(
td
,
cellData
)
{
var
innerHtml
=
cellData
.
length
>
8
?
cellData
.
substring
(
0
,
8
)
+
'...'
:
cellData
;
$
(
td
).
html
(
'<a href="javascript:void(0);" data-toggle="tooltip" title="'
+
cellData
+
'">'
+
innerHtml
+
'</a>'
);
}},
{
targets
:
5
,
createdCell
:
function
(
td
,
cellData
)
{
{
targets
:
5
,
createdCell
:
function
(
td
,
cellData
)
{
if
(
!
cellData
)
{
if
(
!
cellData
)
{
$
(
td
).
html
(
'<i class="fa fa-times text-danger"></i>'
)
$
(
td
).
html
(
'<i class="fa fa-times text-danger"></i>'
)
...
@@ -59,9 +55,13 @@ $(document).ready(function(){
...
@@ -59,9 +55,13 @@ $(document).ready(function(){
}
}
}},
}},
{
targets
:
6
,
createdCell
:
function
(
td
,
cellData
,
rowData
)
{
{
targets
:
6
,
createdCell
:
function
(
td
,
cellData
,
rowData
)
{
var
update_btn
=
'<a href="{% url "terminal:terminal-update" pk=99991937 %}" class="btn btn-xs btn-info">{% trans "Update" %}</a>'
.
replace
(
'99991937'
,
cellData
);
console
.
log
(
rowData
.
name
);
var
del_btn
=
'<a class="btn btn-xs btn-danger m-l-xs btn_user_delete" data-uid="99991937">{% trans "Delete" %}</a>'
.
replace
(
'99991937'
,
cellData
);
var
update_btn
=
'<a href="{% url "terminal:terminal-update" pk=99991937 %}" class="btn btn-xs btn-info">{% trans "Update" %}</a>'
$
(
td
).
html
(
update_btn
+
del_btn
)
.
replace
(
'99991937'
,
cellData
);
var
delete_btn
=
'<a class="btn btn-xs btn-danger m-l-xs btn_delete" data-uid="99991937" data-name="99991938">{% trans "Delete" %}</a>'
.
replace
(
'99991937'
,
cellData
)
.
replace
(
'99991938'
,
rowData
.
name
);
$
(
td
).
html
(
update_btn
+
delete_btn
)
}}
}}
],
],
ajax_url
:
'{% url "terminal:terminal-list-create-api" %}'
,
ajax_url
:
'{% url "terminal:terminal-list-create-api" %}'
,
...
@@ -70,6 +70,12 @@ $(document).ready(function(){
...
@@ -70,6 +70,12 @@ $(document).ready(function(){
op_html
:
$
(
'#actions'
).
html
()
op_html
:
$
(
'#actions'
).
html
()
};
};
jumpserver
.
initDataTable
(
options
);
jumpserver
.
initDataTable
(
options
);
}).
on
(
'click'
,
'.btn_delete'
,
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
);
objectDelete
(
$this
,
name
,
the_url
)
})
})
</script>
</script>
{% endblock %}
{% endblock %}
apps/terminal/urls.py
View file @
6a510dad
...
@@ -16,5 +16,7 @@ urlpatterns = [
...
@@ -16,5 +16,7 @@ urlpatterns = [
urlpatterns
+=
[
urlpatterns
+=
[
url
(
r'^v1/terminal/$'
,
api
.
TerminalCreateListApi
.
as_view
(),
name
=
'terminal-list-create-api'
),
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'
),
]
]
apps/terminal/views.py
View file @
6a510dad
# ~*~ coding: utf-8 ~*~
# ~*~ coding: utf-8 ~*~
#
#
from
django.views.generic
import
ListView
,
UpdateView
from
django.views.generic
import
ListView
,
UpdateView
,
DeleteView
from
django.utils.translation
import
ugettext
as
_
from
django.utils.translation
import
ugettext
as
_
from
django.urls
import
reverse_lazy
from
django.urls
import
reverse_lazy
...
@@ -29,3 +29,9 @@ class TerminalUpdateView(UpdateView):
...
@@ -29,3 +29,9 @@ class TerminalUpdateView(UpdateView):
context
=
super
(
TerminalUpdateView
,
self
)
.
get_context_data
(
**
kwargs
)
context
=
super
(
TerminalUpdateView
,
self
)
.
get_context_data
(
**
kwargs
)
context
.
update
({
'app'
:
_
(
'Terminal'
),
'action'
:
_
(
'Update terminal'
)})
context
.
update
({
'app'
:
_
(
'Terminal'
),
'action'
:
_
(
'Update terminal'
)})
return
context
return
context
class
TerminalDeleteView
(
DeleteView
):
model
=
Terminal
template_name
=
'assets/delete_confirm.html'
success_url
=
reverse_lazy
(
'terminal:terminal-list'
)
\ No newline at end of file
apps/users/backends.py
View file @
6a510dad
...
@@ -41,7 +41,7 @@ class TerminalAuthentication(authentication.BaseAuthentication):
...
@@ -41,7 +41,7 @@ class TerminalAuthentication(authentication.BaseAuthentication):
else
:
else
:
raise
exceptions
.
AuthenticationFailed
(
_
(
'Invalid sign.'
))
raise
exceptions
.
AuthenticationFailed
(
_
(
'Invalid sign.'
))
if
not
terminal
.
is_active
:
if
not
terminal
or
not
terminal
.
is_active
:
raise
exceptions
.
AuthenticationFailed
(
_
(
'Terminal inactive or deleted.'
))
raise
exceptions
.
AuthenticationFailed
(
_
(
'Terminal inactive or deleted.'
))
terminal
.
is_authenticated
=
True
terminal
.
is_authenticated
=
True
return
terminal
,
None
return
terminal
,
None
...
...
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