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
82412831
Commit
82412831
authored
Nov 16, 2016
by
Administrator
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
initial sudo views
parent
d9278c2c
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
178 additions
and
5 deletions
+178
-5
hands.py
apps/ops/hands.py
+15
-0
models.py
apps/ops/models.py
+2
-2
utils.py
apps/ops/utils.py
+41
-1
views.py
apps/ops/views.py
+120
-2
No files found.
apps/ops/hands.py
0 → 100644
View file @
82412831
"""
jumpserver.__app__.hands.py
~~~~~~~~~~~~~~~~~
This app depends other apps api, function .. should be import or write mack here.
Other module of this app shouldn't connect with other app.
:copyright: (c) 2014-2016 by Jumpserver Team.
:license: GPL v2, see LICENSE for more details.
"""
from
users.utils
import
AdminUserRequiredMixin
\ No newline at end of file
apps/ops/models.py
View file @
82412831
...
@@ -334,7 +334,7 @@ class Sudo(models.Model):
...
@@ -334,7 +334,7 @@ class Sudo(models.Model):
"Host_Alias"
:
self
.
hosts
,
"Host_Alias"
:
self
.
hosts
,
"Runas_Alias"
:
self
.
runas
,
"Runas_Alias"
:
self
.
runas
,
"Extra_Lines"
:
self
.
extras
,
"Extra_Lines"
:
self
.
extras
,
"
p
rivileges"
:
self
.
privileges
}
"
P
rivileges"
:
self
.
privileges
}
return
template
.
render
(
context
)
return
template
.
render
(
context
)
@property
@property
...
@@ -392,7 +392,7 @@ root ALL=(ALL:ALL) ALL
...
@@ -392,7 +392,7 @@ root ALL=(ALL:ALL) ALL
# JumpServer Generate User privilege is here.
# JumpServer Generate User privilege is here.
# Note privileges is a tuple list like [(user, host, runas, command, nopassword),]
# Note privileges is a tuple list like [(user, host, runas, command, nopassword),]
{
%
if privileges -
%
}
{
%
if privileges -
%
}
{
%
for User_Flag, Host_Flag, Runas_Flag, Command_Flag, NopassWord in
p
rivileges -
%
}
{
%
for User_Flag, Host_Flag, Runas_Flag, Command_Flag, NopassWord in
P
rivileges -
%
}
{
%
if NopassWord -
%
}
{
%
if NopassWord -
%
}
{{ User_Flag }} {{ Host_Flag }}=({{ Runas_Flag }}) NOPASSWD: {{ Command_Flag }}
{{ User_Flag }} {{ Host_Flag }}=({{ Runas_Flag }}) NOPASSWD: {{ Command_Flag }}
{
%-
else -
%
}
{
%-
else -
%
}
...
...
apps/ops/utils.py
View file @
82412831
# ~*~ coding: utf-8 ~*~
# ~*~ coding: utf-8 ~*~
#
class
CreateHostAliasMinxin
(
object
):
pass
class
CreateUserAliasMinxin
(
object
):
pass
class
CreateCmdAliasMinxin
(
object
):
pass
class
CreateRunasAliasMinxin
(
object
):
pass
class
CreateExtralineAliasMinxin
(
object
):
pass
class
UpdateHostAliasMinxin
(
object
):
pass
class
UpdateUserAliasMinxin
(
object
):
pass
class
UpdateCmdAliasMinxin
(
object
):
pass
class
UpdateRunasAliasMinxin
(
object
):
pass
class
UpdateExtralineAliasMinxin
(
object
):
pass
\ No newline at end of file
apps/ops/views.py
View file @
82412831
from
django.shortcuts
import
render
# ~*~ coding: utf-8 ~*~
from
__future__
import
unicode_literals
# Create your views here.
from
django.conf
import
settings
from
django.views.generic.list
import
ListView
,
MultipleObjectMixin
from
django.views.generic.edit
import
CreateView
,
DeleteView
,
UpdateView
from
django.views.generic.detail
import
DetailView
,
SingleObjectMixin
from
.hands
import
AdminUserRequiredMixin
from
.utils
import
*
class
SudoListView
(
AdminUserRequiredMixin
,
ListView
):
paginate_by
=
settings
.
CONFIG
.
DISPLAY_PER_PAGE
model
=
Asset
context_object_name
=
'asset_list'
template_name
=
'assets/asset_list.html'
def
get_queryset
(
self
):
queryset
=
super
(
AssetListView
,
self
)
.
get_queryset
()
queryset
=
sorted
(
queryset
,
key
=
self
.
sorted_by_valid_and_ip
)
return
queryset
@staticmethod
def
sorted_by_valid_and_ip
(
asset
):
ip_list
=
int_seq
(
asset
.
ip
.
split
(
'.'
))
ip_list
.
insert
(
0
,
asset
.
is_valid
()[
0
])
return
ip_list
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
'app'
:
'Assets'
,
'action'
:
'asset list'
,
'tag_list'
:
[(
i
.
id
,
i
.
name
,
i
.
asset_set
.
all
()
.
count
())
for
i
in
Tag
.
objects
.
all
()
.
order_by
(
'name'
)]
}
kwargs
.
update
(
context
)
return
super
(
AssetListView
,
self
)
.
get_context_data
(
**
kwargs
)
class
SudoCreateView
(
AdminUserRequiredMixin
,
CreateHostAliasMinxin
,
CreateUserAliasMinxin
,
CreateCmdAliasMinxin
,
CreateRunasAliasMinxin
,
CreateExtralineAliasMinxin
,
CreateView
):
model
=
Asset
tag_type
=
'asset'
form_class
=
AssetCreateForm
template_name
=
'assets/asset_create.html'
success_url
=
reverse_lazy
(
'assets:asset-list'
)
def
form_valid
(
self
,
form
):
asset
=
form
.
save
()
asset
.
created_by
=
self
.
request
.
user
.
username
or
'Admin'
asset
.
save
()
return
super
(
AssetCreateView
,
self
)
.
form_valid
(
form
)
def
form_invalid
(
self
,
form
):
print
(
form
.
errors
)
return
super
(
AssetCreateView
,
self
)
.
form_invalid
(
form
)
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
'app'
:
'Assets'
,
'action'
:
'Create asset'
,
}
kwargs
.
update
(
context
)
return
super
(
AssetCreateView
,
self
)
.
get_context_data
(
**
kwargs
)
class
SudoUpdateView
(
AdminUserRequiredMixin
,
UpdateHostAliasMinxin
,
UpdateUserAliasMinxin
,
UpdateCmdAliasMinxin
,
UpdateRunasAliasMinxin
,
UpdateExtralineAliasMinxin
,
UpdateView
):
model
=
Asset
form_class
=
AssetCreateForm
template_name
=
'assets/asset_update.html'
success_url
=
reverse_lazy
(
'assets:asset-list'
)
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
'app'
:
'Assets'
,
'action'
:
'Update asset'
,
}
kwargs
.
update
(
context
)
return
super
(
AssetUpdateView
,
self
)
.
get_context_data
(
**
kwargs
)
def
form_invalid
(
self
,
form
):
print
(
form
.
errors
)
return
super
(
AssetUpdateView
,
self
)
.
form_invalid
(
form
)
class
SudoDeleteView
(
DeleteView
):
model
=
Asset
template_name
=
'assets/delete_confirm.html'
success_url
=
reverse_lazy
(
'assets:asset-list'
)
class
SudoDetailView
(
DetailView
):
model
=
Asset
context_object_name
=
'asset'
template_name
=
'assets/asset_detail.html'
def
get_context_data
(
self
,
**
kwargs
):
asset_groups
=
self
.
object
.
groups
.
all
()
context
=
{
'app'
:
'Assets'
,
'action'
:
'Asset detail'
,
'asset_groups_remain'
:
[
asset_group
for
asset_group
in
AssetGroup
.
objects
.
all
()
if
asset_group
not
in
asset_groups
],
'asset_groups'
:
asset_groups
,
}
kwargs
.
update
(
context
)
return
super
(
AssetDetailView
,
self
)
.
get_context_data
(
**
kwargs
)
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