Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Jpom
Commits
b5099dd2
Commit
b5099dd2
authored
5 years ago
by
不忘初心
Committed by
Gitee
5 years ago
Browse files
Options
Download
Plain Diff
!132 提交JSCH文件管理。。。
Merge pull request !132 from Gongzaixiang/dev
parents
63a03f99
a7b11641
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
modules/server/src/main/java/io/jpom/controller/node/ssh/SshFileController.java
+20
-0
...n/java/io/jpom/controller/node/ssh/SshFileController.java
modules/server/src/main/java/io/jpom/socket/handler/SshHandler.java
+33
-10
...rver/src/main/java/io/jpom/socket/handler/SshHandler.java
modules/server/src/main/resources/templates/node/ssh/file.html
+37
-6
...es/server/src/main/resources/templates/node/ssh/file.html
modules/server/src/main/resources/templates/node/ssh/terminal.html
+21
-5
...erver/src/main/resources/templates/node/ssh/terminal.html
with
111 additions
and
21 deletions
+111
-21
modules/server/src/main/java/io/jpom/controller/node/ssh/SshFileController.java
+
20
-
0
View file @
b5099dd2
...
...
@@ -185,6 +185,26 @@ public class SshFileController extends BaseServerController {
if
(
lsEntry
.
getAttrs
().
isDir
())
{
jsonObject
.
put
(
"dir"
,
true
);
jsonObject
.
put
(
"title"
,
lsEntry
.
getFilename
()
+
"【文件夹】"
);
}
else
if
(
lsEntry
.
getFilename
().
endsWith
(
".gz"
))
{
jsonObject
.
put
(
"gz"
,
true
);
jsonObject
.
put
(
"title"
,
lsEntry
.
getFilename
()
+
"【压缩包】"
);
long
fileSize
=
lsEntry
.
getAttrs
().
getSize
();
jsonObject
.
put
(
"size"
,
FileUtil
.
readableFileSize
(
fileSize
));
}
else
if
(
lsEntry
.
getFilename
().
endsWith
(
".tar"
))
{
jsonObject
.
put
(
"gtar"
,
true
);
jsonObject
.
put
(
"title"
,
lsEntry
.
getFilename
()
+
"【压缩包】"
);
long
fileSize
=
lsEntry
.
getAttrs
().
getSize
();
jsonObject
.
put
(
"size"
,
FileUtil
.
readableFileSize
(
fileSize
));
}
else
if
(
lsEntry
.
getFilename
().
endsWith
(
".rar"
))
{
jsonObject
.
put
(
"rar"
,
true
);
jsonObject
.
put
(
"title"
,
lsEntry
.
getFilename
()
+
"【压缩包】"
);
long
fileSize
=
lsEntry
.
getAttrs
().
getSize
();
jsonObject
.
put
(
"size"
,
FileUtil
.
readableFileSize
(
fileSize
));
}
else
if
(
lsEntry
.
getFilename
().
endsWith
(
".zip"
))
{
jsonObject
.
put
(
"zip"
,
true
);
jsonObject
.
put
(
"title"
,
lsEntry
.
getFilename
()
+
"【压缩包】"
);
long
fileSize
=
lsEntry
.
getAttrs
().
getSize
();
jsonObject
.
put
(
"size"
,
FileUtil
.
readableFileSize
(
fileSize
));
}
else
{
jsonObject
.
put
(
"title"
,
lsEntry
.
getFilename
());
long
fileSize
=
lsEntry
.
getAttrs
().
getSize
();
...
...
This diff is collapsed.
Click to expand it.
modules/server/src/main/java/io/jpom/socket/handler/SshHandler.java
+
33
-
10
View file @
b5099dd2
...
...
@@ -42,17 +42,25 @@ public class SshHandler extends BaseHandler {
public
void
afterConnectionEstablished
(
WebSocketSession
session
)
throws
Exception
{
SshModel
sshItem
=
(
SshModel
)
session
.
getAttributes
().
get
(
"sshItem"
);
Map
<
String
,
String
[]>
parameterMap
=
(
Map
<
String
,
String
[]>)
session
.
getAttributes
().
get
(
"parameterMap"
);
String
[]
tails
=
parameterMap
.
get
(
"tail"
);
//
String
tail
=
null
;
if
(
tails
!=
null
&&
tails
.
length
>
0
&&
!
StrUtil
.
isEmptyOrUndefined
(
tails
[
0
]))
{
tail
=
tails
[
0
];
String
[]
fileDirAlls
=
null
;
//判断url是何操作请求
if
(
parameterMap
.
containsKey
(
"tail"
)){
fileDirAlls
=
parameterMap
.
get
(
"tail"
);
}
else
if
(
parameterMap
.
containsKey
(
"gz"
)){
fileDirAlls
=
parameterMap
.
get
(
"gz"
);
}
else
{
fileDirAlls
=
parameterMap
.
get
(
"zip"
);
}
//检查文件路径
String
fileDirAll
=
null
;
if
(
fileDirAlls
!=
null
&&
fileDirAlls
.
length
>
0
&&
!
StrUtil
.
isEmptyOrUndefined
(
fileDirAlls
[
0
]))
{
fileDirAll
=
fileDirAlls
[
0
];
List
<
String
>
fileDirs
=
sshItem
.
getFileDirs
();
if
(
fileDirs
==
null
)
{
sendBinary
(
session
,
"没有配置路径"
);
return
;
}
File
file
=
FileUtil
.
file
(
tai
l
);
File
file
=
FileUtil
.
file
(
fileDirAl
l
);
boolean
find
=
false
;
for
(
String
fileDir
:
fileDirs
)
{
if
(
FileUtil
.
isSub
(
FileUtil
.
file
(
fileDir
),
file
))
{
...
...
@@ -76,12 +84,27 @@ public class SshHandler extends BaseHandler {
HANDLER_ITEM_CONCURRENT_HASH_MAP
.
put
(
session
.
getId
(),
handlerItem
);
//
Thread
.
sleep
(
1000
);
if
(
tail
==
null
)
{
//截取当前操作文件父路径
String
fileLocalPath
=
null
;
if
(
fileDirAll
.
lastIndexOf
(
"/"
)
>
-
1
){
fileLocalPath
=
fileDirAll
.
substring
(
0
,
fileDirAll
.
lastIndexOf
(
"/"
));
}
if
(
fileDirAll
==
null
)
{
this
.
call
(
session
,
StrUtil
.
CR
);
}
else
{
}
else
if
(
parameterMap
.
containsKey
(
"tail"
))
{
// 查看文件
tail
=
FileUtil
.
normalize
(
tail
);
this
.
call
(
session
,
StrUtil
.
format
(
"tail -f {}"
,
tail
));
fileDirAll
=
FileUtil
.
normalize
(
fileDirAll
);
this
.
call
(
session
,
StrUtil
.
format
(
"tail -f {}"
,
fileDirAll
));
this
.
call
(
session
,
StrUtil
.
CR
);
}
else
if
(
parameterMap
.
containsKey
(
"zip"
)){
//解压zip
fileDirAll
=
FileUtil
.
normalize
(
fileDirAll
);
this
.
call
(
session
,
StrUtil
.
format
(
"unzip -o {} -d "
+
"{}"
,
fileDirAll
,
fileLocalPath
));
this
.
call
(
session
,
StrUtil
.
CR
);
}
else
{
//解压 tar和tar.gz
fileDirAll
=
FileUtil
.
normalize
(
fileDirAll
);
this
.
call
(
session
,
StrUtil
.
format
(
"tar -xzvf {} -C "
+
"{}"
,
fileDirAll
,
fileLocalPath
));
this
.
call
(
session
,
StrUtil
.
CR
);
}
}
...
...
This diff is collapsed.
Click to expand it.
modules/server/src/main/resources/templates/node/ssh/file.html
+
37
-
6
View file @
b5099dd2
...
...
@@ -38,13 +38,21 @@
<table
class=
"layui-table"
id=
"table"
lay-filter=
"table"
style=
"margin: 0;"
></table>
</body>
<script
type=
"text/html"
id=
"bar_monitor"
>
<
a
href
=
"
javascript:;
"
class
=
"
layui-btn layui-btn-sm layui-btn-warm
"
lay
-
event
=
"
terminal
"
>
终端
<
/a
>
{{
#
if
(
!
d
.
path
){
}}
<
a
href
=
"
javascript:;
"
class
=
"
layui-btn layui-btn-sm layui-btn-danger
"
lay
-
event
=
"
delete
"
>
删除
<
/a
>
{{
#
}
}}
{{
#
if
(
!
d
.
dir
&&
!
d
.
gz
&&
!
d
.
tar
&&
!
d
.
zip
&&
!
d
.
rar
){
}}
<
a
href
=
"
javascript:;
"
class
=
"
layui-btn layui-btn-sm layui-btn-warm
"
lay
-
event
=
"
terminal
"
>
终端
<
/a
>
{{
#
}
}}
{{
#
if
(
!
d
.
dir
){
}}
<
a
href
=
"
javascript:;
"
class
=
"
layui-btn layui-btn-sm layui-btn-normal
"
lay
-
event
=
"
download
"
>
下载
<
/a
>
{{
#
}
}}
{{
#
if
(
d
.
zip
){
}}
<
a
href
=
"
javascript:;
"
class
=
"
layui-btn layui-btn-sm layui-btn-normal
"
lay
-
event
=
"
compresszip
"
>
解压
<
/a
>
{{
#
}
}}
{{
#
if
(
d
.
gz
||
d
.
tar
){
}}
<
a
href
=
"
javascript:;
"
class
=
"
layui-btn layui-btn-sm layui-btn-normal
"
lay
-
event
=
"
compressgz
"
>
解压
<
/a
>
{{
#
}
}}
</script>
<script
type=
"text/javascript"
>
var
id
=
getQueryString
(
"
id
"
);
...
...
@@ -52,7 +60,7 @@
var
nowPath
=
''
;
var
rootPath
;
var
col
=
[
{
field
:
'
title
'
,
title
:
'
文件名称
'
,
event
:
'
rowClick
'
},
{
field
:
'
title
'
,
title
:
'
文件名称
'
,
event
:
'
rowClick
'
,
width
:
"
25%
"
,
sort
:
true
},
{
field
:
'
dir
'
,
title
:
'
文件类型
'
,
event
:
'
rowClick
'
,
templet
:
function
(
d
)
{
if
(
d
.
dir
)
{
...
...
@@ -61,9 +69,9 @@
return
'
文件
'
;
}
},
{
field
:
'
size
'
,
title
:
'
文件大小
'
,
event
:
'
rowClick
'
},
{
field
:
'
modifyTime
'
,
title
:
'
修改时间
'
,
event
:
'
rowClick
'
},
{
field
:
'
op
'
,
title
:
'
操作
'
,
align
:
'
center
'
,
toolbar
:
'
#bar_monitor
'
,
fixed
:
'
right
'
}
{
field
:
'
size
'
,
title
:
'
文件大小
'
,
event
:
'
rowClick
'
,
sort
:
true
},
{
field
:
'
modifyTime
'
,
title
:
'
修改时间
'
,
event
:
'
rowClick
'
,
sort
:
true
},
{
field
:
'
op
'
,
title
:
'
操作
'
,
align
:
'
center
'
,
toolbar
:
'
#bar_monitor
'
,
fixed
:
'
right
'
,
width
:
"
30%
"
}
];
function
loadSuccess
()
{
...
...
@@ -94,6 +102,7 @@
if
(
'
download
'
===
event
)
{
// 下载
if
(
!
data
.
dir
)
{
//打开一个浏览器窗口
window
.
open
(
"
./download.html?id=
"
+
id
+
"
&path=
"
+
rootPath
+
"
&name=
"
+
data
.
parentDir
);
}
}
else
if
(
'
terminal
'
===
event
)
{
...
...
@@ -105,7 +114,29 @@
tabChange
({
id
:
id
+
tailPtah
,
url
:
'
./node/ssh/terminal.html?id=
'
+
id
+
"
&tail=
"
+
tailPtah
,
title
:
data
.
name
+
'
- 文件终端
'
,
title
:
data
.
name
+
'
-查看终端
'
,
});
}
else
if
(
'
compresszip
'
===
event
){
let
parentDir
=
formatePath
(
data
.
parentDir
);
var
zipPtah
=
rootPath
+
parentDir
;
if
(
!
rootPath
)
{
tailPtah
=
data
.
path
;
}
tabChange
({
id
:
id
+
zipPtah
,
url
:
'
./node/ssh/terminal.html?id=
'
+
id
+
"
&zip=
"
+
zipPtah
,
title
:
data
.
name
+
'
- zip解压终端
'
,
});
}
else
if
(
'
compressgz
'
===
event
){
let
parentDir
=
formatePath
(
data
.
parentDir
);
var
gzPtah
=
rootPath
+
parentDir
;
if
(
!
rootPath
)
{
gzPtah
=
data
.
path
;
}
tabChange
({
id
:
id
+
gzPtah
,
url
:
'
./node/ssh/terminal.html?id=
'
+
id
+
"
&gz=
"
+
gzPtah
,
title
:
data
.
name
+
'
- gz解压终端
'
,
});
}
else
if
(
'
delete
'
===
event
)
{
let
path
=
rootPath
;
...
...
This diff is collapsed.
Click to expand it.
modules/server/src/main/resources/templates/node/ssh/terminal.html
+
21
-
5
View file @
b5099dd2
...
...
@@ -19,7 +19,11 @@
var
sock
;
// tail 文件
var
tail
=
getQueryString
(
"
tail
"
);
var
zip
=
getQueryString
(
"
zip
"
);
var
gz
=
getQueryString
(
"
gz
"
);
var
cursorBlink
=
!
tail
;
var
cursorBlinkZip
=
!
zip
;
var
cursorBlinkGz
=
!
gz
;
function
loadSuccess
()
{
top
.
layer
.
load
({
...
...
@@ -30,16 +34,28 @@
top
.
location
.
reload
();
}
});
var
url
=
getSocketHost
()
+
"
/ssh?userId=[[${session.user.getUserMd5Key()}]]&
"
+
"
sshId=[[${item?.id}]]&nodeId=system&type=ssh&
"
+
"
tail=
"
+
tail
;
if
(
tail
!==
null
){
var
url
=
getSocketHost
()
+
"
/ssh?userId=[[${session.user.getUserMd5Key()}]]&
"
+
"
sshId=[[${item?.id}]]&nodeId=system&type=ssh&
"
+
"
tail=
"
+
tail
;
}
else
if
(
zip
!==
null
){
var
url
=
getSocketHost
()
+
"
/ssh?userId=[[${session.user.getUserMd5Key()}]]&
"
+
"
sshId=[[${item?.id}]]&nodeId=system&type=ssh&
"
+
"
zip=
"
+
zip
;
}
else
if
(
gz
!==
null
){
var
url
=
getSocketHost
()
+
"
/ssh?userId=[[${session.user.getUserMd5Key()}]]&
"
+
"
sshId=[[${item?.id}]]&nodeId=system&type=ssh&
"
+
"
gz=
"
+
gz
;
}
var
terminal
=
document
.
getElementById
(
"
#terminal
"
);
term
=
new
window
.
Terminal
({
cursorBlink
:
cursorBlink
,
cursorBlinkGz
:
cursorBlinkGz
,
cursorBlinkZip
:
cursorBlinkZip
,
});
//
term
.
onData
(
function
(
data
)
{
if
(
tail
)
{
if
(
tail
||
zip
||
gz
)
{
return
;
}
sock
.
send
(
JSON
.
stringify
({
'
data
'
:
data
}));
...
...
@@ -48,7 +64,7 @@
// 监听按键
var
startX
=
2
;
term
.
onKey
(
function
(
key
)
{
if
(
tail
)
{
if
(
tail
||
zip
||
gz
)
{
return
;
}
var
ev
=
key
.
domEvent
;
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
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