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
61648967
Commit
61648967
authored
Oct 19, 2016
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update some thing
parent
bb9a0672
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
158 additions
and
47 deletions
+158
-47
api.py
apps/terminal/api.py
+4
-4
forms.py
apps/terminal/forms.py
+17
-0
hands.py
apps/terminal/hands.py
+1
-0
models.py
apps/terminal/models.py
+2
-5
serializers.py
apps/terminal/serializers.py
+9
-2
terminal_list.html
apps/terminal/templates/terminal/terminal_list.html
+25
-29
terminal_update.html
apps/terminal/templates/terminal/terminal_update.html
+78
-0
urls.py
apps/terminal/urls.py
+2
-1
views.py
apps/terminal/views.py
+15
-1
_select_user_modal.html
apps/users/templates/users/_select_user_modal.html
+3
-3
user_list.html
apps/users/templates/users/user_list.html
+2
-2
No files found.
apps/terminal/api.py
View file @
61648967
...
...
@@ -11,7 +11,7 @@ from .serializers import TerminalSerializer, TerminalHeatbeatSerializer
from
.hands
import
IsSuperUserOrTerminalUser
class
TerminalApi
(
ListCreateAPIView
):
class
Terminal
CreateList
Api
(
ListCreateAPIView
):
queryset
=
Terminal
.
objects
.
all
()
serializer_class
=
TerminalSerializer
permission_classes
=
(
AllowAny
,)
...
...
@@ -21,20 +21,20 @@ class TerminalApi(ListCreateAPIView):
if
name
:
terminal
=
get_object_or_none
(
Terminal
,
name
=
name
)
if
terminal
:
if
terminal
.
is_ac
cepted
and
terminal
.
is_ac
tive
:
if
terminal
.
is_active
:
return
Response
(
data
=
{
'data'
:
{
'name'
:
name
,
'id'
:
terminal
.
id
},
'msg'
:
'Success'
},
status
=
200
)
else
:
return
Response
(
data
=
{
'data'
:
{
'name'
:
name
,
'ip'
:
terminal
.
ip
},
'msg'
:
'Need admin ac
cept or ac
tive it'
},
'msg'
:
'Need admin active it'
},
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 ac
cept or ac
tive it'
},
'msg'
:
'Need admin active it'
},
status
=
204
)
else
:
return
Response
(
data
=
{
'msg'
:
'Secrete key invalid'
},
status
=
401
)
...
...
apps/terminal/forms.py
0 → 100644
View file @
61648967
# ~*~ coding: utf-8 ~*~
#
from
django
import
forms
from
django.utils.translation
import
ungettext_lazy
as
_
from
.models
import
Terminal
class
TerminalForm
(
forms
.
ModelForm
):
class
Meta
:
model
=
Terminal
fields
=
[
'name'
,
'ip'
,
'is_active'
,
'type'
,
'url'
,
'comment'
]
help_texts
=
{
'url'
:
'Example: ssh://192.168.1.1:22 or http://jms.jumpserver.org, that user login'
}
apps/terminal/hands.py
View file @
61648967
...
...
@@ -2,4 +2,5 @@
#
from
users.backends
import
IsSuperUserOrTerminalUser
from
audits.models
import
ProxyLog
apps/terminal/models.py
View file @
61648967
...
...
@@ -15,13 +15,10 @@ class Terminal(models.Model):
ip
=
models
.
GenericIPAddressField
(
verbose_name
=
_
(
'From ip'
))
is_active
=
models
.
BooleanField
(
default
=
False
,
verbose_name
=
_
(
'Is active'
))
is_bound_ip
=
models
.
BooleanField
(
default
=
False
,
verbose_name
=
_
(
'Is bound ip'
))
heatbeat_interval
=
models
.
IntegerField
(
default
=
60
,
verbose_name
=
_
(
'Heatbeat interval'
))
type
=
models
.
CharField
(
choices
=
TYPE_CHOICES
,
max_length
=
2
,
verbose_name
=
_
(
'Terminal type'
))
url
=
models
.
CharField
(
max_length
=
100
,
verbose_name
=
_
(
'URL to login'
))
mail_to
=
models
.
ManyToManyField
(
User
,
verbose_name
=
_
(
'Mail to'
))
is_accepted
=
models
.
BooleanField
(
default
=
False
,
verbose_name
=
_
(
'Is accepted'
))
date_created
=
models
.
DateTimeField
(
auto_now_add
=
True
)
comment
=
models
.
TextField
(
verbose_name
=
_
(
'Comment'
))
comment
=
models
.
TextField
(
blank
=
True
,
verbose_name
=
_
(
'Comment'
))
def
is_valid
(
self
):
return
self
.
is_active
and
self
.
is_accepted
...
...
@@ -36,7 +33,7 @@ class Terminal(models.Model):
class
Meta
:
db_table
=
'terminal'
ordering
=
[
'
nam
e'
]
ordering
=
[
'
is_activ
e'
]
class
TerminalHeatbeat
(
models
.
Model
):
...
...
apps/terminal/serializers.py
View file @
61648967
...
...
@@ -4,13 +4,20 @@
from
rest_framework
import
serializers
from
.models
import
Terminal
,
TerminalHeatbeat
from
.hands
import
ProxyLog
class
TerminalSerializer
(
serializers
.
ModelSerializer
):
proxy_amount
=
serializers
.
SerializerMethodField
()
class
Meta
:
model
=
Terminal
fields
=
[
'name'
,
'ip'
,
'type'
,
'url'
,
'comment'
,
'is_active'
,
'is_accepted'
,
'get_type_display'
]
fields
=
[
'id'
,
'name'
,
'ip'
,
'type'
,
'url'
,
'comment'
,
'is_active'
,
'get_type_display'
,
'proxy_amount'
]
@staticmethod
def
get_proxy_amount
(
obj
):
return
ProxyLog
.
objects
.
filter
(
terminal
=
obj
.
name
,
is_finished
=
False
)
.
count
()
class
TerminalHeatbeatSerializer
(
serializers
.
ModelSerializer
):
...
...
apps/terminal/templates/terminal/terminal_list.html
View file @
61648967
...
...
@@ -27,7 +27,7 @@
<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 '
url
' %}
</th>
<th
class=
"text-center"
>
{% trans '
proxy_amount
' %}
</th>
<th
class=
"text-center"
>
{% trans 'Active' %}
</th>
<th
class=
"text-center"
>
{% trans 'Action' %}
</th>
</tr>
...
...
@@ -36,41 +36,37 @@
</tbody>
</table>
{% endblock %}
{% block content_bottom_left %}{% endblock %}
{% block custom_foot_js %}
<script
src=
"{% static 'js/jquery.form.min.js' %}"
></script>
<script>
$
(
document
).
ready
(
function
(){
var
options
=
{
ele
:
$
(
'#terminal_list_table'
),
{
#
columnDefs
:
[
#
}
{
#
{
targets
:
1
,
createdCell
:
function
(
td
,
cellData
,
rowData
)
{
#
}
{
#
var
detail_btn
=
'<a href="{% url "users:user-detail" pk=99991937 %}">'
+
cellData
+
'</a>'
;
#
}
{
#
$
(
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
:
6
,
createdCell
:
function
(
td
,
cellData
)
{
#
}
{
#
if
(
!
cellData
)
{
#
}
{
#
$
(
td
).
html
(
'<i class="fa fa-times text-danger"></i>'
)
#
}
{
#
}
else
{
#
}
{
#
$
(
td
).
html
(
'<i class="fa fa-check text-navy"></i>'
)
#
}
{
#
}
#
}
{
#
}},
#
}
{
#
{
targets
:
7
,
createdCell
:
function
(
td
,
cellData
,
rowData
)
{
#
}
{
#
var
update_btn
=
'<a href="{% url "users:user-update" pk=99991937 %}" class="btn btn-xs btn-info">{% trans "Update" %}</a>'
.
replace
(
'99991937'
,
cellData
);
#
}
{
#
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
);
#
}
{
#
if
(
rowData
.
id
===
1
)
{
#
}
{
#
$
(
td
).
html
(
update_btn
)
#
}
{
#
}
else
{
#
}
{
#
$
(
td
).
html
(
update_btn
+
del_btn
)
#
}
{
#
}}],
#
}
{
#
],
#
}
columnDefs
:
[
{
targets
:
1
,
createdCell
:
function
(
td
,
cellData
,
rowData
)
{
var
detail_btn
=
'<a href="{% url "users:user-detail" pk=99991937 %}">'
+
cellData
+
'</a>'
;
$
(
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
)
{
if
(
!
cellData
)
{
$
(
td
).
html
(
'<i class="fa fa-times text-danger"></i>'
)
}
else
{
$
(
td
).
html
(
'<i class="fa fa-check text-navy"></i>'
)
}
}},
{
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
);
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
);
$
(
td
).
html
(
update_btn
+
del_btn
)
}}
],
ajax_url
:
'{% url "terminal:terminal-list-create-api" %}'
,
columns
:
[{
data
:
function
(){
return
""
}},
{
data
:
"name"
},
{
data
:
"ip"
},
{
data
:
"get_type_display"
},
{
data
:
"url"
},
{
data
:
"
is_active"
},
{
data
:
"ip
"
}],
columns
:
[{
data
:
function
(){
return
""
}},
{
data
:
"name"
},
{
data
:
"ip"
},
{
data
:
"get_type_display"
},
{
data
:
"
proxy_amount"
},
{
data
:
"is_active"
},
{
data
:
"id
"
}],
op_html
:
$
(
'#actions'
).
html
()
};
jumpserver
.
initDataTable
(
options
);
...
...
apps/terminal/templates/terminal/terminal_update.html
0 → 100644
View file @
61648967
{% extends 'base.html' %}
{% load i18n %}
{% load static %}
{% load bootstrap %}
{% block custom_head_css_js %}
<link
href=
"{% static "
css
/
plugins
/
select2
/
select2
.
min
.
css
"
%}"
rel=
"stylesheet"
>
<script
src=
"{% static "
js
/
plugins
/
select2
/
select2
.
full
.
min
.
js
"
%}"
></script>
<link
href=
"{% static "
css
/
plugins
/
datepicker
/
datepicker3
.
css
"
%}"
rel=
"stylesheet"
>
{% endblock %}
{% block content %}
<div
class=
"wrapper wrapper-content animated fadeInRight"
>
<div
class=
"row"
>
<div
class=
"col-sm-12"
>
<div
class=
"ibox float-e-margins"
>
<div
class=
"ibox-title"
>
<h5>
{{ action }}
</h5>
<div
class=
"ibox-tools"
>
<a
class=
"collapse-link"
>
<i
class=
"fa fa-chevron-up"
></i>
</a>
<a
class=
"dropdown-toggle"
data-toggle=
"dropdown"
href=
"#"
>
<i
class=
"fa fa-wrench"
></i>
</a>
<a
class=
"close-link"
>
<i
class=
"fa fa-times"
></i>
</a>
</div>
</div>
<div
class=
"ibox-content"
>
<form
method=
"post"
class=
"form-horizontal"
action=
""
enctype=
"multipart/form-data"
>
{% csrf_token %}
<h3>
{% trans 'Info' %}
</h3>
{{ form.name|bootstrap_horizontal }}
{{ form.ip|bootstrap_horizontal }}
{{ form.type|bootstrap_horizontal }}
{{ form.url|bootstrap_horizontal }}
<div
class=
"hr-line-dashed"
></div>
<h3>
{% trans 'Other' %}
</h3>
<div
class=
"form-group"
>
<label
for=
"{{ form.is_active.id_for_label }}"
class=
"col-sm-2 control-label"
>
{% trans 'Active' %}
</label>
<div
class=
"col-sm-8"
>
{{ form.is_active}}
</div>
</div>
{{ form.comment|bootstrap_horizontal }}
<div
class=
"hr-line-dashed"
></div>
<div
class=
"form-group"
>
<div
class=
"col-sm-4 col-sm-offset-2"
>
<button
class=
"btn btn-white"
type=
"reset"
>
{% trans 'Reset' %}
</button>
<button
id=
"submit_button"
class=
"btn btn-primary"
type=
"submit"
>
{% trans 'Submit' %}
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
{% block custom_foot_js %}
<script
src=
"{% static 'js/plugins/datapicker/bootstrap-datepicker.js' %}"
></script>
<script>
$
(
document
).
ready
(
function
()
{
$
(
'.select2'
).
select2
();
$
(
'.input-group.date'
).
datepicker
({
format
:
"yyyy-mm-dd"
,
todayBtn
:
"linked"
,
keyboardNavigation
:
false
,
forceParse
:
false
,
calendarWeeks
:
true
,
autoclose
:
true
});
})
</script>
{% endblock %}
apps/terminal/urls.py
View file @
61648967
...
...
@@ -11,9 +11,10 @@ app_name = 'terminal'
urlpatterns
=
[
url
(
r'^terminal$'
,
views
.
TerminalListView
.
as_view
(),
name
=
'terminal-list'
),
url
(
r'^terminal/(?P<pk>\d+)/update$'
,
views
.
TerminalUpdateView
.
as_view
(),
name
=
'terminal-update'
),
]
urlpatterns
+=
[
url
(
r'^v1/terminal/$'
,
api
.
TerminalApi
.
as_view
(),
name
=
'terminal-list-create-api'
),
url
(
r'^v1/terminal/$'
,
api
.
Terminal
CreateList
Api
.
as_view
(),
name
=
'terminal-list-create-api'
),
url
(
r'^v1/terminal-heatbeat/$'
,
api
.
TerminalHeatbeatApi
.
as_view
(),
name
=
'terminal-heatbeat-api'
),
]
apps/terminal/views.py
View file @
61648967
# ~*~ coding: utf-8 ~*~
#
from
django.views.generic
import
ListView
from
django.views.generic
import
ListView
,
UpdateView
from
django.utils.translation
import
ugettext
as
_
from
django.urls
import
reverse_lazy
from
.models
import
Terminal
from
.forms
import
TerminalForm
class
TerminalListView
(
ListView
):
...
...
@@ -15,3 +17,15 @@ class TerminalListView(ListView):
context
=
super
(
TerminalListView
,
self
)
.
get_context_data
(
**
kwargs
)
context
.
update
({
'app'
:
_
(
'Terminal'
),
'action'
:
_
(
'Terminal list'
)})
return
context
class
TerminalUpdateView
(
UpdateView
):
model
=
Terminal
form_class
=
TerminalForm
template_name
=
'terminal/terminal_update.html'
success_url
=
reverse_lazy
(
'terminal:terminal-list'
)
def
get_context_data
(
self
,
**
kwargs
):
context
=
super
(
TerminalUpdateView
,
self
)
.
get_context_data
(
**
kwargs
)
context
.
update
({
'app'
:
_
(
'Terminal'
),
'action'
:
_
(
'Update terminal'
)})
return
context
apps/users/templates/users/_select_user_modal.html
View file @
61648967
...
...
@@ -10,12 +10,12 @@
<th
class=
"text-center"
>
<div
class=
"checkbox checkbox-default"
><input
id=
""
type=
"checkbox"
class=
"ipt_check_all"
><label></label></div>
</th>
<th
class=
"text-center"
>
{% trans 'Name' %}
</
a></
th>
<th
class=
"text-center"
>
{% trans 'Username' %}
</
a></
th>
<th
class=
"text-center"
>
{% trans 'Name' %}
</th>
<th
class=
"text-center"
>
{% trans 'Username' %}
</th>
<th
class=
"text-center"
>
{% trans 'Role' %}
</th>
<th
class=
"text-center"
>
{% trans 'User group' %}
</th>
<th
class=
"text-center"
>
{% trans 'Asset num' %}
</th>
<th
class=
"text-center"
>
{% trans 'Active' %}
</
a></
th>
<th
class=
"text-center"
>
{% trans 'Active' %}
</th>
</tr>
</thead>
</table>
...
...
apps/users/templates/users/user_list.html
View file @
61648967
...
...
@@ -92,7 +92,7 @@ $(document).ready(function(){
jumpserver
.
initDataTable
(
options
);
}).
on
(
'click'
,
'#btn_bulk_update'
,
function
(){
var
action
=
$
(
'#slct_bulk_update'
).
val
();
var
$data_table
=
$
(
'#user_list_table'
).
DataTable
()
var
$data_table
=
$
(
'#user_list_table'
).
DataTable
()
;
var
id_list
=
[];
var
plain_id_list
=
[];
$data_table
.
rows
({
selected
:
true
}).
every
(
function
(){
...
...
@@ -101,7 +101,7 @@ $(document).ready(function(){
});
if
(
id_list
===
[])
{
return
false
;
}
;
}
var
the_url
=
"{% url 'users:user-bulk-update-api' %}"
;
function
doDeactive
()
{
var
body
=
$
.
each
(
id_list
,
function
(
index
,
user_object
)
{
...
...
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