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
0fcbd9fd
Commit
0fcbd9fd
authored
Aug 12, 2019
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[UPdate] 解决命令执行宽度问题
parent
f46ccb50
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
54 additions
and
6 deletions
+54
-6
callback.py
apps/ops/ansible/callback.py
+5
-0
command.py
apps/ops/api/command.py
+4
-1
inventory.py
apps/ops/inventory.py
+0
-3
tasks.py
apps/ops/tasks.py
+4
-0
command_execution_create.html
apps/ops/templates/ops/command_execution_create.html
+41
-2
No files found.
apps/ops/ansible/callback.py
View file @
0fcbd9fd
...
...
@@ -2,6 +2,7 @@
import
datetime
import
json
import
os
from
collections
import
defaultdict
from
ansible
import
constants
as
C
...
...
@@ -41,7 +42,11 @@ class CallbackMixin:
super
()
.
__init__
()
if
display
:
self
.
_display
=
display
cols
=
os
.
environ
.
get
(
"TERM_COLS"
,
None
)
self
.
_display
.
columns
=
79
if
cols
and
cols
.
isdigit
():
self
.
_display
.
columns
=
int
(
cols
)
-
1
def
display
(
self
,
msg
):
self
.
_display
.
display
(
msg
)
...
...
apps/ops/api/command.py
View file @
0fcbd9fd
...
...
@@ -29,6 +29,9 @@ class CommandExecutionViewSet(RootOrgViewMixin, viewsets.ModelViewSet):
instance
=
serializer
.
save
()
instance
.
user
=
self
.
request
.
user
instance
.
save
()
cols
=
self
.
request
.
query_params
.
get
(
"cols"
,
'80'
)
rows
=
self
.
request
.
query_params
.
get
(
"rows"
,
'24'
)
transaction
.
on_commit
(
lambda
:
run_command_execution
.
apply_async
(
args
=
(
instance
.
id
,),
task_id
=
str
(
instance
.
id
)
args
=
(
instance
.
id
,),
kwargs
=
{
"cols"
:
cols
,
"rows"
:
rows
},
task_id
=
str
(
instance
.
id
)
))
apps/ops/inventory.py
View file @
0fcbd9fd
...
...
@@ -30,8 +30,6 @@ class JMSBaseInventory(BaseInventory):
info
.
update
(
asset
.
get_auth_info
())
if
asset
.
is_unixlike
():
info
[
"become"
]
=
asset
.
admin_user
.
become_info
for
node
in
asset
.
nodes
.
all
():
info
[
"groups"
]
.
append
(
node
.
value
)
if
asset
.
is_windows
():
info
[
"vars"
]
.
update
({
"ansible_connection"
:
"ssh"
,
...
...
@@ -45,7 +43,6 @@ class JMSBaseInventory(BaseInventory):
info
[
"vars"
]
.
update
({
"domain"
:
asset
.
domain
.
name
,
})
info
[
"groups"
]
.
append
(
"domain_"
+
asset
.
domain
.
name
)
return
info
@staticmethod
...
...
apps/ops/tasks.py
View file @
0fcbd9fd
...
...
@@ -45,6 +45,10 @@ def run_command_execution(cid, **kwargs):
execution
=
get_object_or_none
(
CommandExecution
,
id
=
cid
)
if
execution
:
try
:
os
.
environ
.
update
({
"TERM_ROWS"
:
kwargs
.
get
(
"rows"
,
""
),
"TERM_COLS"
:
kwargs
.
get
(
"cols"
,
""
),
})
execution
.
run
()
except
SoftTimeLimitExceeded
:
logger
.
error
(
"Run time out"
)
...
...
apps/ops/templates/ops/command_execution_create.html
View file @
0fcbd9fd
...
...
@@ -85,6 +85,41 @@ var systemUserId = null;
var
url
=
null
;
var
treeUrl
=
"{% url 'api-perms:my-nodes-assets-as-tree' %}?cache_policy=1"
;
function
proposeGeometry
(
term
)
{
if
(
!
term
.
element
.
parentElement
)
{
return
null
;
}
var
parentElementStyle
=
window
.
getComputedStyle
(
term
.
element
.
parentElement
);
var
parentElementHeight
=
parseInt
(
parentElementStyle
.
getPropertyValue
(
'height'
));
var
parentElementWidth
=
Math
.
max
(
0
,
parseInt
(
parentElementStyle
.
getPropertyValue
(
'width'
)));
var
elementStyle
=
window
.
getComputedStyle
(
term
.
element
);
var
elementPadding
=
{
top
:
parseInt
(
elementStyle
.
getPropertyValue
(
'padding-top'
)),
bottom
:
parseInt
(
elementStyle
.
getPropertyValue
(
'padding-bottom'
)),
right
:
parseInt
(
elementStyle
.
getPropertyValue
(
'padding-right'
)),
left
:
parseInt
(
elementStyle
.
getPropertyValue
(
'padding-left'
))
};
var
elementPaddingVer
=
elementPadding
.
top
+
elementPadding
.
bottom
;
var
elementPaddingHor
=
elementPadding
.
right
+
elementPadding
.
left
;
var
availableHeight
=
parentElementHeight
-
elementPaddingVer
;
var
availableWidth
=
parentElementWidth
-
elementPaddingHor
-
term
.
_core
.
viewport
.
scrollBarWidth
;
var
geometry
=
{
cols
:
Math
.
floor
(
availableWidth
/
term
.
_core
.
renderer
.
dimensions
.
actualCellWidth
),
rows
:
Math
.
floor
(
availableHeight
/
term
.
_core
.
renderer
.
dimensions
.
actualCellHeight
)
};
return
geometry
;
}
function
fit
(
term
)
{
var
geometry
=
proposeGeometry
(
term
);
if
(
geometry
)
{
if
(
term
.
rows
!==
geometry
.
rows
||
term
.
cols
!==
geometry
.
cols
)
{
term
.
_core
.
renderer
.
clear
();
term
.
resize
(
geometry
.
cols
,
geometry
.
rows
);
}
}
}
function
initTree
()
{
var
setting
=
{
check
:
{
...
...
@@ -183,6 +218,7 @@ function initResultTerminal() {
screenKeys
:
false
,
fontFamily
:
'monaco, Consolas, "Lucida Console", monospace'
,
fontSize
:
14
,
lineHeight
:
1
,
rightClickSelectsWord
:
true
,
disableStdin
:
true
,
theme
:
{
...
...
@@ -190,7 +226,9 @@ function initResultTerminal() {
}
});
term
.
open
(
document
.
getElementById
(
'term'
));
term
.
write
(
"{% trans 'Select the left asset, select the running system user, execute command in batch' %}"
+
"
\
r
\n
"
)
var
msg
=
"{% trans 'Select the left asset, select the running system user, execute command in batch' %}"
+
"
\
r
\n
"
;
fit
(
term
);
term
.
write
(
msg
)
}
function
wrapperError
(
msg
)
{
...
...
@@ -201,7 +239,8 @@ function execute() {
if
(
!
term
)
{
initResultTerminal
()
}
var
url
=
'{% url "api-ops:command-execution-list" %}'
;
var
size
=
'rows='
+
term
.
rows
+
'&cols='
+
term
.
cols
;
var
url
=
'{% url "api-ops:command-execution-list" %}?'
+
size
;
var
run_as
=
systemUserId
;
var
command
=
editor
.
getValue
();
var
hosts
=
getSelectedAssetsNode
().
map
(
function
(
node
)
{
...
...
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