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
52e5487e
Commit
52e5487e
authored
Dec 10, 2018
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 修改执行命令
parent
d6b22e9f
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
59 additions
and
23 deletions
+59
-23
base.py
apps/assets/models/base.py
+3
-0
callback.py
apps/ops/ansible/callback.py
+18
-8
runner.py
apps/ops/ansible/runner.py
+20
-1
command_execution_create.html
apps/ops/templates/ops/command_execution_create.html
+17
-14
_nav.html
apps/templates/_nav.html
+1
-0
No files found.
apps/assets/models/base.py
View file @
52e5487e
...
...
@@ -105,6 +105,9 @@ class AssetUser(OrgModelMixin):
if
update_fields
:
self
.
save
(
update_fields
=
update_fields
)
def
get_auth
(
self
,
asset
=
None
):
pass
def
clear_auth
(
self
):
self
.
_password
=
''
self
.
_private_key
=
''
...
...
apps/ops/ansible/callback.py
View file @
52e5487e
...
...
@@ -139,16 +139,17 @@ class AdHocResultCallback(CallbackMixin, CallbackModule, CMDCallBackModule):
class
CommandResultCallback
(
AdHocResultCallback
):
"""
Command result callback
results_command: {
"cmd": "",
"stderr": "",
"stdout": "",
"rc": 0,
"delta": 0:0:0.123
}
"""
def
__init__
(
self
,
display
=
None
,
**
kwargs
):
# results_command: {
# "cmd": "",
# "stderr": "",
# "stdout": "",
# "rc": 0,
# "delta": 0:0:0.123
# }
#
self
.
results_command
=
dict
()
super
()
.
__init__
(
display
)
...
...
@@ -156,6 +157,15 @@ class CommandResultCallback(AdHocResultCallback):
super
()
.
gather_result
(
t
,
res
)
self
.
gather_cmd
(
t
,
res
)
def
v2_playbook_on_play_start
(
self
,
play
):
now
=
datetime
.
datetime
.
now
()
.
strftime
(
'
%
Y-
%
m-
%
d
%
H:
%
M:
%
S'
)
msg
=
'$ {} ({})'
.
format
(
'echo'
,
now
)
self
.
_play
=
play
self
.
_display
.
banner
(
msg
)
def
_print_task_banner
(
self
,
task
):
pass
def
gather_cmd
(
self
,
t
,
res
):
host
=
res
.
_host
.
get_name
()
cmd
=
{}
...
...
apps/ops/ansible/runner.py
View file @
52e5487e
...
...
@@ -135,6 +135,7 @@ class AdHocRunner:
loader_class
=
DataLoader
variable_manager_class
=
VariableManager
default_options
=
get_default_options
()
command_modules_choices
=
(
'shell'
,
'raw'
,
'command'
,
'script'
,
'win_shell'
)
def
__init__
(
self
,
inventory
,
options
=
None
):
self
.
options
=
self
.
update_options
(
options
)
...
...
@@ -163,10 +164,28 @@ class AdHocRunner:
"pattern:
%
s dose not match any hosts."
%
pattern
)
def
clean_args
(
self
,
module
,
args
):
if
module
not
in
self
.
command_modules_choices
:
return
args
if
isinstance
(
args
,
str
):
if
args
.
startswith
(
'executable='
):
_args
=
args
.
split
(
' '
)
executable
,
command
=
_args
[
0
]
.
split
(
'='
)[
1
],
' '
.
join
(
_args
[
1
:])
args
=
{
'executable'
:
executable
,
'_raw_params'
:
command
}
else
:
args
=
{
'_raw_params'
:
args
}
return
args
else
:
return
args
def
clean_tasks
(
self
,
tasks
):
cleaned_tasks
=
[]
for
task
in
tasks
:
self
.
check_module_args
(
task
[
'action'
][
'module'
],
task
[
'action'
]
.
get
(
'args'
))
module
=
task
[
'action'
][
'module'
]
args
=
task
[
'action'
]
.
get
(
'args'
)
cleaned_args
=
self
.
clean_args
(
module
,
args
)
task
[
'action'
][
'args'
]
=
cleaned_args
self
.
check_module_args
(
module
,
cleaned_args
)
cleaned_tasks
.
append
(
task
)
return
cleaned_tasks
...
...
apps/ops/templates/ops/command_execution_create.html
View file @
52e5487e
...
...
@@ -46,7 +46,7 @@
</div>
</div>
<div
class=
"mail-box-header"
style=
"padding-top: 5px;"
>
<form
enctype=
"multipart/form-data"
method=
"post"
class=
"form-horizontal"
action=
""
>
<form
enctype=
"multipart/form-data"
method=
"post"
class=
"form-horizontal"
action=
""
onsubmit=
"return execute()"
>
<div
class=
"form-group"
>
<div
id=
"term"
style=
"height: 100%;width: 100%"
></div>
</div>
...
...
@@ -180,16 +180,7 @@ function initResultTerminal() {
term
.
write
(
"选择左侧资产, 选择运行的系统用户,批量执行命令
\
r
\n
"
)
}
$
(
document
).
ready
(
function
(){
systemUserId
=
$
(
'#system-users-select'
).
val
();
$
(
".select2"
).
select2
().
on
(
'select2:select'
,
function
(
evt
)
{
var
data
=
evt
.
params
.
data
;
systemUserId
=
data
.
id
;
initTree
();
});
initTree
();
initResultTerminal
();
}).
on
(
'click'
,
'.btn-execute'
,
function
()
{
function
execute
()
{
if
(
!
term
)
{
initResultTerminal
()
}
...
...
@@ -247,8 +238,21 @@ $(document).ready(function(){
writeExecutionOutput
()
},
interval
);
}
})
});
return
false
;
}
$
(
document
).
ready
(
function
(){
systemUserId
=
$
(
'#system-users-select'
).
val
();
$
(
".select2"
).
select2
().
on
(
'select2:select'
,
function
(
evt
)
{
var
data
=
evt
.
params
.
data
;
systemUserId
=
data
.
id
;
initTree
();
});
initTree
();
initResultTerminal
();
}).
on
(
'click'
,
'.btn-execute'
,
function
()
{
execute
()
})
</script>
{% endblock %}
\ No newline at end of file
apps/templates/_nav.html
View file @
52e5487e
...
...
@@ -64,6 +64,7 @@
</a>
<ul
class=
"nav nav-second-level"
>
<li
id=
"task"
><a
href=
"{% url 'ops:task-list' %}"
>
{% trans 'Task list' %}
</a></li>
<li
id=
"command-execution-start"
><a
href=
"{% url 'ops:command-execution-start' %}"
>
{% trans 'Command execution' %}
</a></li>
</ul>
</li>
<li
id=
"audits"
>
...
...
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