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
8e0afb2c
Commit
8e0afb2c
authored
Nov 27, 2016
by
Administrator
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
调整模型
parent
2494fa58
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
30 additions
and
17 deletions
+30
-17
api_router.py
apps/jumpserver/api_router.py
+10
-10
urls.py
apps/jumpserver/urls.py
+2
-2
sudo.py
apps/ops/models/sudo.py
+16
-3
views.py
apps/ops/views.py
+1
-1
_nav.html
apps/templates/_nav.html
+1
-1
No files found.
apps/jumpserver/api_router.py
View file @
8e0afb2c
from
rest_framework.routers
import
DefaultRouter
from
ops.api
import
views
as
ops_api_view
router
=
DefaultRouter
()
router
.
register
(
r'host_alia'
,
ops_api_view
.
HostAliaViewSet
)
router
.
register
(
r'user_alia'
,
ops_api_view
.
UserAliaViewSet
)
router
.
register
(
r'cmd_alia'
,
ops_api_view
.
CmdAliaViewSet
)
router
.
register
(
r'runas_alia'
,
ops_api_view
.
RunasAliaViewSet
)
router
.
register
(
r'extra_conf'
,
ops_api_view
.
ExtraconfViewSet
)
router
.
register
(
r'privilege'
,
ops_api_view
.
PrivilegeViewSet
)
router
.
register
(
r'sudo'
,
ops_api_view
.
SudoViewSet
)
router
.
register
(
r'cron'
,
ops_api_view
.
CronTableViewSet
)
\ No newline at end of file
api_router
=
DefaultRouter
()
api_router
.
register
(
r'host_alia'
,
ops_api_view
.
HostAliaViewSet
)
api_router
.
register
(
r'user_alia'
,
ops_api_view
.
UserAliaViewSet
)
api_router
.
register
(
r'cmd_alia'
,
ops_api_view
.
CmdAliaViewSet
)
api_router
.
register
(
r'runas_alia'
,
ops_api_view
.
RunasAliaViewSet
)
api_router
.
register
(
r'extra_conf'
,
ops_api_view
.
ExtraconfViewSet
)
api_router
.
register
(
r'privilege'
,
ops_api_view
.
PrivilegeViewSet
)
api_router
.
register
(
r'sudo'
,
ops_api_view
.
SudoViewSet
)
api_router
.
register
(
r'cron'
,
ops_api_view
.
CronTableViewSet
)
\ No newline at end of file
apps/jumpserver/urls.py
View file @
8e0afb2c
...
...
@@ -20,7 +20,7 @@ from django.conf.urls import url, include
from
django.conf
import
settings
from
django.conf.urls.static
import
static
from
django.views.generic.base
import
TemplateView
from
jumpserver.api_router
import
router
from
jumpserver.api_router
import
api_
router
urlpatterns
=
[
...
...
@@ -41,7 +41,7 @@ urlpatterns = [
urlpatterns
+=
[
url
(
r'^api/v1/ops'
,
include
(
router
.
urls
)),
url
(
r'^api/v1/ops'
,
include
(
api_
router
.
urls
)),
url
(
r'^ops/'
,
include
(
'ops.urls'
,
namespace
=
'ops'
)),
]
...
...
apps/ops/models/sudo.py
View file @
8e0afb2c
...
...
@@ -3,7 +3,7 @@ from __future__ import unicode_literals, absolute_import
from
jinja2
import
Template
from
django.db
import
models
from
assets.models
import
Asset
from
assets.models
import
Asset
,
AssetGroup
from
django.utils.translation
import
ugettext_lazy
as
_
...
...
@@ -40,11 +40,13 @@ class RunasAlia(models.Model):
class
Privilege
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
128
,
unique
=
True
,
verbose_name
=
_
(
'Name'
))
user
=
models
.
ForeignKey
(
UserAlia
,
blank
=
True
,
null
=
True
,
related_name
=
'privileges'
)
host
=
models
.
ForeignKey
(
HostAlia
,
blank
=
True
,
null
=
True
,
related_name
=
'privileges'
)
runas
=
models
.
ForeignKey
(
RunasAlia
,
blank
=
True
,
null
=
True
,
related_name
=
'privileges'
)
command
=
models
.
ForeignKey
(
CmdAlia
,
blank
=
True
,
null
=
True
,
related_name
=
'privileges'
)
nopassword
=
models
.
BooleanField
(
default
=
True
,
verbose_name
=
_
(
'Is_NoPassword'
))
comment
=
models
.
TextField
(
blank
=
True
,
null
=
True
,
verbose_name
=
_
(
'Comment'
))
def
__unicode__
(
self
):
return
"[
%
s
%
s
%
s
%
s
%
s]"
%
(
self
.
user
.
name
,
...
...
@@ -58,7 +60,8 @@ class Privilege(models.Model):
class
Extra_conf
(
models
.
Model
):
line
=
models
.
TextField
(
blank
=
True
,
null
=
True
,
verbose_name
=
_
(
'Extra_Item'
))
line
=
models
.
TextField
(
blank
=
True
,
null
=
True
,
verbose_name
=
_
(
'Extra_Item'
),
help_text
=
_
(
'The extra sudo config line.'
))
def
__unicode__
(
self
):
return
self
.
line
...
...
@@ -72,10 +75,20 @@ class Sudo(models.Model):
:param privileges: <list> [(user, host, runas, command, nopassword),]
"""
asset
=
models
.
ForeignKey
(
Asset
,
null
=
True
,
blank
=
True
,
related_name
=
'sudos'
)
assets
=
models
.
ManyToManyField
(
Asset
,
blank
=
True
,
related_name
=
'sudos'
)
asset_groups
=
models
.
ManyToManyField
(
AssetGroup
,
blank
=
True
,
related_name
=
'sudos'
)
extra_lines
=
models
.
ManyToManyField
(
Extra_conf
,
related_name
=
'sudos'
,
blank
=
True
)
privilege_items
=
models
.
ManyToManyField
(
Privilege
,
related_name
=
'sudos'
,
blank
=
True
)
@property
def
all_assets
(
self
):
assets
=
list
(
self
.
assets
.
all
())
for
group
in
self
.
asset_groups
.
all
():
for
asset
in
group
.
assets
.
all
():
if
asset
not
in
assets
:
assets
.
append
(
asset
)
return
assets
@property
def
users
(
self
):
return
{
privilege
.
user
.
name
:
privilege
.
user
.
user_items
.
split
(
','
)
for
privilege
in
self
.
privilege_items
.
all
()}
...
...
apps/ops/views.py
View file @
8e0afb2c
...
...
@@ -53,6 +53,6 @@ class CronUpdateView(AdminUserRequiredMixin, UpdateView):
class
CronDetailView
(
DetailView
):
model
=
CronTable
context_object_name
=
'
sudo
'
context_object_name
=
'
cron
'
template_name
=
'cron/detail.html'
apps/templates/_nav.html
View file @
8e0afb2c
...
...
@@ -43,7 +43,7 @@
<li
id=
"ops"
>
<a>
<i
class=
"fa fa-
inbox
"
></i>
<span
class=
"nav-label"
>
{% trans 'Job Center' %}
</span><span
class=
"fa arrow"
></span>
<i
class=
"fa fa-
coffee
"
></i>
<span
class=
"nav-label"
>
{% trans 'Job Center' %}
</span><span
class=
"fa arrow"
></span>
</a>
<ul
class=
"nav nav-second-level"
>
<li
id=
"sudo"
><a
href=
"{% url 'ops:page-sudo-list' %}"
>
{% trans 'Sudo' %}
</a></li>
...
...
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