Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
antSword
Project
Project
Details
Activity
Releases
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
HuangJunbo
antSword
Commits
9a0fbbd7
Commit
9a0fbbd7
authored
Apr 14, 2016
by
antoor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix call core module
修复调用核心模块
parent
b6092dde
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
660 additions
and
462 deletions
+660
-462
app.entry.jsx
source/app.entry.jsx
+1
-3
index.jsx
source/modules/database/asp/index.jsx
+42
-26
index.jsx
source/modules/database/custom/index.jsx
+40
-26
index.jsx
source/modules/database/php/index.jsx
+48
-36
files.jsx
source/modules/filemanager/files.jsx
+18
-0
folder.jsx
source/modules/filemanager/folder.jsx
+13
-2
index.jsx
source/modules/filemanager/index.jsx
+320
-210
index.jsx
source/modules/terminal/index.jsx
+178
-159
No files found.
source/app.entry.jsx
View file @
9a0fbbd7
...
...
@@ -33,9 +33,7 @@ const antSword = window.antSword = {
};
// 加载模板代码
[
'php'
,
'asp'
,
'aspx'
,
'custom'
].
map
((
_
)
=>
{
antSword
[
'core'
][
_
]
=
require
(
`./core/
${
_
}
/index`
);
});
antSword
[
'core'
]
=
require
(
'./core/index'
);
// 加载显示语言
let
_lang
=
localStorage
.
getItem
(
'language'
)
||
navigator
.
language
;
...
...
source/modules/database/asp/index.jsx
View file @
9a0fbbd7
...
...
@@ -254,11 +254,15 @@ class ASP {
_id
:
this
.
manager
.
opt
[
'_id'
],
id
:
id
});
this
.
core
.
request
(
this
.
core
[
`database_
${
conf
[
'type'
]}
`
].
show_databases
(
{
conn
:
conf
[
'conn'
],
dbname
:
[
'access'
,
'microsoft_jet_oledb_4_0'
].
indexOf
(
conf
[
'type'
])
>
-
1
?
conf
[
'conn'
].
match
(
/
[\w]
+.mdb$/
)
:
'database'
},
(
ret
)
=>
{
})
).
then
((
res
)
=>
{
let
ret
=
res
[
'text'
];
const
arr
=
ret
.
split
(
'
\
t'
);
if
(
arr
.
length
===
1
&&
ret
===
''
)
{
toastr
.
warning
(
'执行完毕,没有结果返回'
)
...
...
@@ -279,7 +283,7 @@ class ASP {
this
.
manager
.
list
.
imgs
[
1
]);
});
this
.
manager
.
list
.
layout
.
progressOff
();
}
,
(
err
)
=>
{
}
).
catch
(
(
err
)
=>
{
toastr
.
error
(
'获取数据库列表失败!'
+
err
[
'status'
]
||
JSON
.
stringify
(
err
),
'ERROR'
);
this
.
manager
.
list
.
layout
.
progressOff
();
});
...
...
@@ -293,11 +297,15 @@ class ASP {
_id
:
this
.
manager
.
opt
[
'_id'
],
id
:
id
});
this
.
core
.
request
(
this
.
core
[
`database_
${
conf
[
'type'
]}
`
].
show_tables
(
{
conn
:
conf
[
'conn'
],
dbname
:
db
},
(
ret
)
=>
{
})
).
then
((
res
)
=>
{
let
ret
=
res
[
'text'
];
const
arr
=
ret
.
split
(
'
\
t'
);
const
_db
=
new
Buffer
(
db
).
toString
(
'base64'
);
// 删除子节点
...
...
@@ -328,11 +336,15 @@ class ASP {
_id
:
this
.
manager
.
opt
[
'_id'
],
id
:
id
});
this
.
core
.
request
(
this
.
core
[
`database_
${
conf
[
'type'
]}
`
].
show_columns
(
{
conn
:
conf
[
'conn'
],
table
:
conf
[
'type'
]
===
'oracle'
?
`SELECT * FROM (SELECT A.*,ROWNUM N FROM
${
table
}
A) WHERE N=1`
:
`SELECT TOP 1 * FROM
${
table
}
`
},
(
ret
)
=>
{
})
).
then
((
res
)
=>
{
let
ret
=
res
[
'text'
];
const
arr
=
ret
.
split
(
'
\
t'
);
const
_db
=
new
Buffer
(
db
).
toString
(
'base64'
);
const
_table
=
new
Buffer
(
table
).
toString
(
'base64'
);
...
...
@@ -363,14 +375,18 @@ class ASP {
// 执行SQL
execSQL
(
sql
)
{
this
.
manager
.
query
.
layout
.
progressOn
();
this
.
core
.
request
(
this
.
core
[
`database_
${
this
.
dbconf
[
'type'
]}
`
].
query
({
conn
:
this
.
dbconf
[
'conn'
],
sql
:
sql
},
(
ret
)
=>
{
})
).
then
((
res
)
=>
{
let
ret
=
res
[
'text'
];
// 更新执行结果
this
.
updateResult
(
ret
);
this
.
manager
.
query
.
layout
.
progressOff
();
}
,
(
err
)
=>
{
}
).
catch
(
(
err
)
=>
{
console
.
error
(
err
);
});
}
...
...
source/modules/database/custom/index.jsx
View file @
9a0fbbd7
...
...
@@ -250,12 +250,14 @@ class ASP {
_id
:
this
.
manager
.
opt
[
'_id'
],
id
:
id
});
this
.
core
[
`database_
${
conf
[
'type'
]}
`
].
show_databases
(
{
this
.
core
.
request
(
this
.
core
[
`database_
${
conf
[
'type'
]}
`
].
show_databases
(
{
conn
:
conf
[
'conn'
],
encode
:
this
.
manager
.
opt
.
encode
,
db
:
[
'access'
,
'microsoft_jet_oledb_4_0'
].
indexOf
(
conf
[
'type'
])
>
-
1
?
conf
[
'conn'
].
match
(
/
[\w]
+.mdb$/
)
:
'database'
},
(
ret
)
=>
{
})
).
then
((
res
)
=>
{
let
ret
=
res
[
'text'
];
const
arr
=
ret
.
split
(
'
\
t'
);
if
(
arr
.
length
===
1
&&
ret
===
''
)
{
toastr
.
warning
(
'执行完毕,没有结果返回'
)
...
...
@@ -276,7 +278,7 @@ class ASP {
this
.
manager
.
list
.
imgs
[
1
]);
});
this
.
manager
.
list
.
layout
.
progressOff
();
}
,
(
err
)
=>
{
}
).
catch
(
(
err
)
=>
{
toastr
.
error
(
'获取数据库列表失败!'
+
err
[
'status'
]
||
JSON
.
stringify
(
err
),
'ERROR'
);
this
.
manager
.
list
.
layout
.
progressOff
();
});
...
...
@@ -290,12 +292,16 @@ class ASP {
_id
:
this
.
manager
.
opt
[
'_id'
],
id
:
id
});
this
.
core
.
request
(
this
.
core
[
`database_
${
conf
[
'type'
]}
`
].
show_tables
(
{
conn
:
conf
[
'conn'
],
encode
:
this
.
manager
.
opt
.
encode
,
db
:
db
},
(
ret
)
=>
{
})
).
then
((
res
)
=>
{
let
ret
=
res
[
'text'
];
const
arr
=
ret
.
split
(
'
\
t'
);
const
_db
=
new
Buffer
(
db
).
toString
(
'base64'
);
// 删除子节点
...
...
@@ -326,13 +332,17 @@ class ASP {
_id
:
this
.
manager
.
opt
[
'_id'
],
id
:
id
});
this
.
core
.
request
(
this
.
core
[
`database_
${
conf
[
'type'
]}
`
].
show_columns
(
{
conn
:
conf
[
'conn'
],
encode
:
this
.
manager
.
opt
.
encode
,
db
:
db
,
table
:
table
},
(
ret
)
=>
{
})
).
then
((
res
)
=>
{
let
ret
=
res
[
'text'
];
const
arr
=
ret
.
split
(
'
\
t'
);
const
_db
=
new
Buffer
(
db
).
toString
(
'base64'
);
const
_table
=
new
Buffer
(
table
).
toString
(
'base64'
);
...
...
@@ -363,15 +373,19 @@ class ASP {
// 执行SQL
execSQL
(
sql
)
{
this
.
manager
.
query
.
layout
.
progressOn
();
this
.
core
.
request
(
this
.
core
[
`database_
${
this
.
dbconf
[
'type'
]}
`
].
query
({
conn
:
this
.
dbconf
[
'conn'
],
encode
:
this
.
manager
.
opt
.
encode
,
sql
:
sql
},
(
ret
)
=>
{
})
).
then
((
res
)
=>
{
let
ret
=
res
[
'text'
];
// 更新执行结果
this
.
updateResult
(
ret
);
this
.
manager
.
query
.
layout
.
progressOff
();
}
,
(
err
)
=>
{
}
).
catch
(
(
err
)
=>
{
console
.
error
(
err
);
});
}
...
...
source/modules/database/php/index.jsx
View file @
9a0fbbd7
...
...
@@ -271,12 +271,14 @@ class PHP {
_id
:
this
.
manager
.
opt
[
'_id'
],
id
:
id
});
this
.
core
[
`database_
${
conf
[
'type'
]}
`
].
show_databases
(
{
this
.
core
.
request
(
this
.
core
[
`database_
${
conf
[
'type'
]}
`
].
show_databases
(
{
host
:
conf
[
'host'
],
user
:
conf
[
'user'
],
passwd
:
conf
[
'passwd'
]
},
(
ret
)
=>
{
})
).
then
((
res
)
=>
{
let
ret
=
res
[
'text'
];
const
arr
=
ret
.
split
(
'
\
t'
);
if
(
arr
.
length
===
1
&&
ret
===
''
)
{
toastr
.
warning
(
LANG
[
'result'
][
'warning'
],
LANG_T
[
'warning'
]);
...
...
@@ -297,7 +299,7 @@ class PHP {
this
.
manager
.
list
.
imgs
[
1
]);
});
this
.
manager
.
list
.
layout
.
progressOff
();
}
,
(
err
)
=>
{
}
).
catch
(
(
err
)
=>
{
toastr
.
error
(
LANG
[
'result'
][
'error'
][
'database'
](
err
[
'status'
]
||
JSON
.
stringify
(
err
)),
LANG_T
[
'error'
]);
this
.
manager
.
list
.
layout
.
progressOff
();
});
...
...
@@ -311,13 +313,16 @@ class PHP {
_id
:
this
.
manager
.
opt
[
'_id'
],
id
:
id
});
this
.
core
[
`database_
${
conf
[
'type'
]}
`
].
show_tables
(
{
this
.
core
.
request
(
this
.
core
[
`database_
${
conf
[
'type'
]}
`
].
show_tables
({
host
:
conf
[
'host'
],
user
:
conf
[
'user'
],
passwd
:
conf
[
'passwd'
],
db
:
db
},
(
ret
)
=>
{
})
).
then
((
res
)
=>
{
let
ret
=
res
[
'text'
];
const
arr
=
ret
.
split
(
'
\
t'
);
const
_db
=
new
Buffer
(
db
).
toString
(
'base64'
);
// 删除子节点
...
...
@@ -337,7 +342,7 @@ class PHP {
);
});
this
.
manager
.
list
.
layout
.
progressOff
();
}
,
(
err
)
=>
{
}
).
catch
(
(
err
)
=>
{
toastr
.
error
(
LANG
[
'result'
][
'error'
][
'table'
](
err
[
'status'
]
||
JSON
.
stringify
(
err
)),
LANG_T
[
'error'
]);
this
.
manager
.
list
.
layout
.
progressOff
();
});
...
...
@@ -351,14 +356,17 @@ class PHP {
_id
:
this
.
manager
.
opt
[
'_id'
],
id
:
id
});
this
.
core
[
`database_
${
conf
[
'type'
]}
`
].
show_columns
(
{
this
.
core
.
request
(
this
.
core
[
`database_
${
conf
[
'type'
]}
`
].
show_columns
({
host
:
conf
[
'host'
],
user
:
conf
[
'user'
],
passwd
:
conf
[
'passwd'
],
db
:
db
,
table
:
table
},
(
ret
)
=>
{
})
).
then
((
res
)
=>
{
let
ret
=
res
[
'text'
];
const
arr
=
ret
.
split
(
'
\
t'
);
const
_db
=
new
Buffer
(
db
).
toString
(
'base64'
);
const
_table
=
new
Buffer
(
table
).
toString
(
'base64'
);
...
...
@@ -380,7 +388,7 @@ class PHP {
// 更新编辑器SQL语句
this
.
manager
.
query
.
editor
.
session
.
setValue
(
`SELECT * FROM \`
${
table
}
\` ORDER BY 1 DESC LIMIT 0,20;`
);
this
.
manager
.
list
.
layout
.
progressOff
();
}
,
(
err
)
=>
{
}
).
catch
(
(
err
)
=>
{
toastr
.
error
(
LANG
[
'result'
][
'error'
][
'column'
](
err
[
'status'
]
||
JSON
.
stringify
(
err
)),
LANG_T
[
'error'
]);
this
.
manager
.
list
.
layout
.
progressOff
();
});
...
...
@@ -389,6 +397,8 @@ class PHP {
// 执行SQL
execSQL
(
sql
)
{
this
.
manager
.
query
.
layout
.
progressOn
();
this
.
core
.
request
(
this
.
core
[
`database_
${
this
.
dbconf
[
'type'
]}
`
].
query
({
host
:
this
.
dbconf
[
'host'
],
user
:
this
.
dbconf
[
'user'
],
...
...
@@ -396,11 +406,13 @@ class PHP {
db
:
this
.
dbconf
[
'database'
],
sql
:
sql
,
encode
:
this
.
dbconf
[
'encode'
]
||
'utf8'
},
(
ret
)
=>
{
})
).
then
((
res
)
=>
{
let
ret
=
res
[
'text'
];
// 更新执行结果
this
.
updateResult
(
ret
);
this
.
manager
.
query
.
layout
.
progressOff
();
}
,
(
err
)
=>
{
}
).
catch
(
(
err
)
=>
{
toastr
.
error
(
LANG
[
'result'
][
'error'
][
'query'
](
err
[
'status'
]
||
JSON
.
stringify
(
err
)),
LANG_T
[
'error'
]);
this
.
manager
.
query
.
layout
.
progressOff
();
});
...
...
source/modules/filemanager/files.jsx
View file @
9a0fbbd7
...
...
@@ -194,6 +194,7 @@ class Files {
grid
.
setInitWidths
(
"40,*,150,100,100"
);
grid
.
setColAlign
(
"center,left,left,right,center"
);
grid
.
enableMultiselect
(
true
);
grid
.
enableDragAndDrop
(
true
);
// grid.enableMultiline(true);
// grid右键
...
...
@@ -368,6 +369,23 @@ class Files {
// 剪贴板
this
.
Clipboard
=
{};
// 文件拖拽上传
$
(
this
.
cell
.
cell
).
on
({
dragleave
:
(
e
)
=>
{
e
.
preventDefault
()
},
drop
:
(
e
)
=>
{
e
.
preventDefault
();
let
filePaths
=
[];
let
files
=
e
.
originalEvent
[
'dataTransfer'
][
'files'
]
||
{};
for
(
let
i
=
0
;
i
<
files
.
length
;
i
++
)
{
let
f
=
files
.
item
(
i
);
filePaths
.
push
(
f
[
'path'
]);
}
this
.
manager
.
uploadFile
(
filePaths
);
},
dragenter
:
(
e
)
=>
{
e
.
preventDefault
()
},
dragover
:
(
e
)
=>
{
e
.
preventDefault
()
}
});
}
// 刷新当前目录
...
...
source/modules/filemanager/folder.jsx
View file @
9a0fbbd7
...
...
@@ -11,7 +11,6 @@ class Folder {
// 1.cell: 左侧layout.cell对象
constructor
(
cell
,
manager
)
{
cell
.
setWidth
(
250
);
cell
.
setText
(
`<i class="fa fa-folder-o"></i>
${
LANG
[
'title'
]}
`
);
// 创建tree
let
tree
=
cell
.
attachTree
();
// tree事件
...
...
@@ -23,6 +22,7 @@ class Folder {
this
.
cell
=
cell
;
this
.
cache
=
{};
this
.
manager
=
manager
;
this
.
setTitle
(
0
);
}
...
...
@@ -44,12 +44,15 @@ class Folder {
self
.
cache
[
curPath
]
=
0
;
});
// 2. 解析当前子目录
let
folderNum
=
0
;
files
.
map
((
f
)
=>
{
let
_
=
f
[
'name'
];
if
(
!
_
.
endsWith
(
'/'
)
||
[
'./'
,
'../'
].
indexOf
(
_
)
!==
-
1
)
{
return
};
self
.
cache
[
`
${
curPath
}${
_
}
`
]
=
0
;
folderNum
++
;
});
// 设置标题
this
.
setTitle
(
folderNum
);
// 3. 解析缓存为树形菜单虚拟对象
// /var/www/html 根据/分割为数组,循环,相加,增加到虚拟缓存
...
...
@@ -100,6 +103,14 @@ class Folder {
this
.
cell
.
progressOff
();
}
/**
* 设置标题
* @param {Number} num 当前目录数
*/
setTitle
(
num
)
{
this
.
cell
.
setText
(
`<i class="fa fa-folder-o"></i>
${
LANG
[
'title'
]}
(
${
num
}
)`
);
}
}
export
default
Folder
;
source/modules/filemanager/index.jsx
View file @
9a0fbbd7
//
// 文件管理模块
//
/**
* 文件管理模板
* 更新:2016/04/13
* 作者:蚁逅 <https://github.com/antoor>
*/
'use strict'
;
import
Files
from
'./files'
;
import
Tasks
from
'./tasks'
;
...
...
@@ -25,13 +28,15 @@ class FileManager {
tabbar
.
addTab
(
`tab_filemanager_
${
hash
}
`
,
// `<i class="fa fa-folder-o"></i> ${LANG['title']} \/\/ ${opts['ip']}`,
`<i class="fa fa-folder-o"></i>
${
opts
[
'ip'
]}
`
,
null
,
null
,
true
,
true
);
// 创建框架
const
cell
=
tabbar
.
cells
(
`tab_filemanager_
${
hash
}
`
);
// 增加到全局变量方便调试
antSword
[
'modules'
][
'filemanager'
]
=
antSword
[
'modules'
][
'filemanager'
]
||
{};
antSword
[
'modules'
][
'filemanager'
][
hash
]
=
this
;
this
.
isWin
=
true
;
this
.
path
=
'/'
;
...
...
@@ -51,14 +56,24 @@ class FileManager {
this
.
initUI
(
cache_info
);
}
else
{
this
.
cell
.
progressOn
();
this
.
core
.
base
.
info
((
ret
)
=>
{
this
.
initUI
(
ret
);
this
.
core
.
request
(
this
.
core
.
base
.
info
()
).
then
((
ret
)
=>
{
this
.
initUI
(
ret
[
'text'
]);
this
.
cell
.
progressOff
();
}
,
(
err
)
=>
{
}
).
catch
(
(
err
)
=>
{
this
.
cell
.
progressOff
();
this
.
cell
.
close
();
toastr
.
error
((
typeof
(
err
)
===
'object'
)
?
JSON
.
stringify
(
err
)
:
String
(
err
),
LANG_T
[
'error'
]);
});
// this.core.base.info((ret) => {
// this.initUI(ret);
// this.cell.progressOff();
// }, (err) => {
// this.cell.progressOff();
// this.cell.close();
// toastr.error((typeof(err) === 'object') ? JSON.stringify(err) : String(err), LANG_T['error']);
// });
}
}
...
...
@@ -131,9 +146,12 @@ class FileManager {
return
callback
(
JSON
.
parse
(
cache
));
};
this
.
core
.
request
(
this
.
core
.
filemanager
.
dir
({
path
:
path
},
(
ret
)
=>
{
})
).
then
((
res
)
=>
{
let
ret
=
res
[
'text'
];
// 判断是否出错
if
(
ret
.
startsWith
(
'ERROR://'
))
{
callback
([]);
...
...
@@ -167,9 +185,49 @@ class FileManager {
// 增加缓存
// self.cache[path] = data;
this
.
cache
.
set
(
cache_tag
,
JSON
.
stringify
(
data
));
}
,
(
err
)
=>
{
}
).
catch
(
(
err
)
=>
{
toastr
.
error
((
err
instanceof
Object
)
?
JSON
.
stringify
(
err
)
:
String
(
err
),
LANG_T
[
'error'
]);
});
})
// this.core.filemanager.dir({
// path: path
// }, (ret) => {
// // 判断是否出错
// if (ret.startsWith('ERROR://')) {
// callback([]);
// return toastr.error(ret.substr(9), LANG_T['error']);
// };
// let tmp = ret.split('\n');
//
// tmp.sort();
//
// let folders = [];
// let files = [];
//
// tmp.map( (t) => {
// let _ = t.split('\t');
// let d = {
// name: _[0],
// time: _[1],
// size: _[2],
// attr: _[3]
// }
// if (_[0].endsWith('/')) {
// folders.push(d);
// }else{
// files.push(d);
// }
// } );
//
// let data = folders.concat(files);
// callback(data);
//
// // 增加缓存
// // self.cache[path] = data;
// this.cache.set(cache_tag, JSON.stringify(data));
// }, (err) => {
// toastr.error((err instanceof Object) ? JSON.stringify(err) : String(err), LANG_T['error']);
// });
}
// 更改目录,返回最终绝对路径
...
...
@@ -225,9 +283,12 @@ class FileManager {
((
p
)
=>
{
const
path
=
this
.
path
+
p
;
this
.
files
.
cell
.
progressOn
();
this
.
core
.
request
(
this
.
core
.
filemanager
.
delete
({
path
:
path
},
(
ret
)
=>
{
})
).
then
((
res
)
=>
{
let
ret
=
res
[
'text'
];
this
.
files
.
cell
.
progressOff
();
if
(
ret
===
'1'
)
{
toastr
.
success
(
LANG
[
'delete'
][
'success'
](
path
),
LANG_T
[
'success'
]);
...
...
@@ -235,10 +296,24 @@ class FileManager {
}
else
{
toastr
.
error
(
LANG
[
'delete'
][
'error'
](
path
,
ret
===
'0'
?
false
:
ret
),
LANG_T
[
'error'
]);
}
}
,
(
err
)
=>
{
}
).
catch
(
(
err
)
=>
{
this
.
files
.
cell
.
progressOff
();
toastr
.
error
(
LANG
[
'delete'
][
'error'
](
path
,
err
),
LANG_T
[
'error'
]);
})
});
// this.core.filemanager.delete({
// path: path
// }, (ret) => {
// this.files.cell.progressOff();
// if (ret === '1') {
// toastr.success(LANG['delete']['success'](path), LANG_T['success']);
// this.files.refreshPath();
// }else{
// toastr.error(LANG['delete']['error'](path, ret === '0' ? false : ret), LANG_T['error']);
// }
// }, (err) => {
// this.files.cell.progressOff();
// toastr.error(LANG['delete']['error'](path, err), LANG_T['error']);
// })
})(
p
);
});
}
...
...
@@ -254,10 +329,13 @@ class FileManager {
const
target
=
this
.
path
+
name
;
this
.
files
.
cell
.
progressOn
();
this
.
core
.
request
(
this
.
core
.
filemanager
.
copy
({
path
:
source
,
target
:
target
},
(
ret
)
=>
{
})
).
then
((
res
)
=>
{
let
ret
=
res
[
'text'
];
this
.
files
.
cell
.
progressOff
();
if
(
ret
===
'1'
)
{
// 刷新目录
...
...
@@ -268,7 +346,7 @@ class FileManager {
}
else
{
toastr
.
error
(
LANG
[
'paste'
][
'error'
](
name
,
ret
===
'0'
?
false
:
ret
),
LANG_T
[
'error'
]);
}
}
,
(
err
)
=>
{
}
).
catch
(
(
err
)
=>
{
toastr
.
error
(
LANG
[
'paste'
][
'error'
](
name
,
err
),
LANG_T
[
'error'
]);
});
}
...
...
@@ -281,10 +359,13 @@ class FileManager {
title
:
`<i class="fa fa-fa fa-font"></i>
${
LANG
[
'rename'
][
'title'
]}
(
${
antSword
.
noxss
(
name
)}
)`
},
(
value
,
index
,
elem
)
=>
{
this
.
files
.
cell
.
progressOn
();
this
.
core
.
request
(
this
.
core
.
filemanager
.
rename
({
path
:
this
.
path
+
name
,
name
:
this
.
path
+
value
+
((
isDir
&&
!
value
.
endsWith
(
'/'
))
?
'/'
:
''
)
},
(
ret
)
=>
{
})
).
then
((
res
)
=>
{
let
ret
=
res
[
'text'
];
this
.
files
.
cell
.
progressOff
();
if
(
ret
===
'1'
)
{
this
.
files
.
refreshPath
();
...
...
@@ -292,7 +373,7 @@ class FileManager {
}
else
{
toastr
.
error
(
LANG
[
'rename'
][
'error'
](
ret
===
'0'
?
false
:
ret
),
LANG_T
[
'error'
]);
}
}
,
(
err
)
=>
{
}
).
catch
(
(
err
)
=>
{
toastr
.
error
(
LANG
[
'rename'
][
'error'
](
err
),
LANG_T
[
'error'
]);
});
layer
.
close
(
index
);
...
...
@@ -306,9 +387,12 @@ class FileManager {
title
:
`<i class="fa fa-folder"></i>
${
LANG
[
'createFolder'
][
'title'
]}
`
},
(
value
,
i
,
e
)
=>
{
this
.
files
.
cell
.
progressOn
();
this
.
core
.
request
(
this
.
core
.
filemanager
.
mkdir
({
path
:
this
.
path
+
value
},
(
ret
)
=>
{
})
).
then
((
res
)
=>
{
let
ret
=
res
[
'text'
];
this
.
files
.
cell
.
progressOff
();
if
(
ret
===
'1'
)
{
this
.
files
.
refreshPath
();
...
...
@@ -316,7 +400,7 @@ class FileManager {
}
else
{
toastr
.
error
(
LANG
[
'createFolder'
][
'error'
](
value
,
ret
===
'0'
?
false
:
ret
),
LANG_T
[
'error'
]);
}
}
,
(
err
)
=>
{
}
).
catch
(
(
err
)
=>
{
toastr
.
error
(
LANG
[
'createFolder'
][
'error'
](
value
,
err
),
LANG_T
[
'error'
]);
});
layer
.
close
(
i
);
...
...
@@ -330,10 +414,15 @@ class FileManager {
title
:
`<i class="fa fa-file"></i>
${
LANG
[
'createFile'
][
'title'
]}
`
},
(
value
,
i
,
e
)
=>
{
this
.
files
.
cell
.
progressOn
();
// 发起http请求
this
.
core
.
request
(
this
.
core
.
filemanager
.
create_file
({
path
:
this
.
path
+
value
,
content
:
'
\
0'
},
(
ret
)
=>
{
content
:
'Halo ANT!'
})
).
then
((
res
)
=>
{
let
ret
=
res
[
'text'
];
this
.
files
.
cell
.
progressOff
();
if
(
ret
===
'1'
)
{
this
.
files
.
refreshPath
();
...
...
@@ -341,7 +430,7 @@ class FileManager {
}
else
{
toastr
.
error
(
LANG
[
'createFile'
][
'error'
](
value
,
ret
===
'0'
?
false
:
ret
),
LANG_T
[
'error'
]);
}
}
,
(
err
)
=>
{
}
).
catch
(
(
err
)
=>
{
toastr
.
error
(
LANG
[
'createFile'
][
'error'
](
value
,
err
),
LANG_T
[
'error'
]);
});
layer
.
close
(
i
);
...
...
@@ -356,10 +445,15 @@ class FileManager {
content
:
`<input type="text" class="layui-layer-input" onClick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'});" value="
${
oldtime
}
">`
},
(
value
,
i
,
e
)
=>
{
this
.
files
.
cell
.
progressOn
();
// http request
this
.
core
.
request
(
this
.
core
.
filemanager
.
retime
({
path
:
this
.
path
+
name
,
time
:
value
},
(
ret
)
=>
{
})
).
then
((
res
)
=>
{
let
ret
=
res
[
'text'
];
this
.
files
.
cell
.
progressOff
();
if
(
ret
===
'1'
)
{
this
.
files
.
refreshPath
();
...
...
@@ -367,7 +461,7 @@ class FileManager {
}
else
{
toastr
.
error
(
LANG
[
'retime'
][
'error'
](
name
,
ret
===
'0'
?
false
:
ret
),
LANG_T
[
'error'
]);
}
}
,
(
err
)
=>
{
}
).
catch
(
(
err
)
=>
{
toastr
.
error
(
LANG
[
'retime'
][
'error'
](
name
,
err
),
LANG_T
[
'error'
]);
});
layer
.
close
(
i
);
...
...
@@ -384,16 +478,18 @@ class FileManager {
win
.
cell
.
lastChild
[
'style'
][
'textAlign'
]
=
'center'
;
let
data
=
'data:image/png;base64,'
;
let
buff
=
''
;
this
.
core
.
filemanager
.
download_file
({
path
:
path
},
(
ret
,
buff
)
=>
{
let
imgData
=
new
Buffer
(
buff
).
toString
(
'base64'
);
win
.
attachHTMLString
(
`<img src="data:/image/png;base64,
${
imgData
}
"/>`
);
},
(
err
)
=>
{
},
(
chunk
)
=>
{
this
.
core
.
request
(
this
.
core
.
filemanager
.
download_file
()
,
(
chunk
)
=>
{
buff
+=
chunk
;
let
imgData
=
data
+
new
Buffer
(
buff
).
toString
(
'base64'
);
}
).
then
((
res
)
=>
{
let
imgData
=
new
Buffer
(
res
[
'buff'
]).
toString
(
'base64'
);
win
.
attachHTMLString
(
`<img src="data:/image/png;base64,
${
imgData
}
"/>`
);
}).
catch
((
err
)
=>
{
});
}
...
...
@@ -408,41 +504,39 @@ class FileManager {
},
(
filePath
)
=>
{
if
(
!
filePath
)
{
return
task
.
end
(
LANG
[
'download'
][
'task'
][
'cancel'
])
};
task
.
update
(
LANG
[
'download'
][
'task'
][
'start'
]);
// setTimeout(() => {
let
down_size
=
0
;
this
.
core
.
filemanager
.
download_file
({
path
:
path
},
(
ret
,
buff
)
=>
{
// 保存文件
// fs.writeFileSync(filePath+'_bak', new global.Buffer(buff));
// 检测文件大小是否一致
if
(
buff
.
length
===
size
)
{
task
.
success
(
LANG
[
'download'
][
'task'
][
'success'
]);
toastr
.
success
(
LANG
[
'download'
][
'success'
](
name
),
LANG_T
[
'success'
]);
}
else
if
(
buff
.
length
===
21
)
{
task
.
failed
(
buff
.
toString
());
}
else
{
// task.failed(`FileSize(${buff.length} != ${size}`);
task
.
failed
(
LANG
[
'download'
][
'task'
][
'error'
](
`SizeErr:
${
buff
.
length
}
!=
${
size
}
`
))
// 删除旧文件(如果存在
if
(
fs
.
existsSync
(
filePath
))
{
fs
.
unlinkSync
(
filePath
);
}
},
(
err
)
=>
{
task
.
failed
(
LANG
[
'download'
][
'task'
][
'error'
](
err
));
toastr
.
error
(
LANG
[
'download'
][
'error'
](
name
,
err
),
LANG_T
[
'error'
]);
},
(
chunk
)
=>
{
// 写入文件
fs
.
writeFileSync
(
filePath
,
new
global
.
Buffer
(
chunk
),
{
flag
:
'a'
});
this
.
core
.
download
(
filePath
,
this
.
core
.
filemanager
.
download_file
({
path
:
path
})
,
(
_size
)
=>
{
// 计算进度百分比
down_size
+=
chunk
.
length
;
down_size
+=
_size
;
let
down_progress
=
parseInt
(
parseFloat
(
down_size
/
size
).
toFixed
(
2
)
*
100
);
if
(
!
(
down_progress
%
5
))
{
task
.
update
(
down_progress
+
'%'
);
};
// task.update(`${parseFloat(down_size/size).toFixed(0) * 100} %`);
}
).
then
((
_size
)
=>
{
if
(
_size
===
size
)
{
task
.
success
(
LANG
[
'download'
][
'task'
][
'success'
]);
toastr
.
success
(
LANG
[
'download'
][
'success'
](
name
),
LANG_T
[
'success'
]);
// }else if (_size === 21) {
// task.failed('len=' + _size);
}
else
{
throw
Error
(
`SizeErr:
${
_size
}
!=
${
size
}
`
);
// task.failed(LANG['download']['task']['error']())
}
}).
catch
((
err
)
=>
{
task
.
failed
(
LANG
[
'download'
][
'task'
][
'error'
](
err
));
toastr
.
error
(
LANG
[
'download'
][
'error'
](
name
,
err
),
LANG_T
[
'error'
]);
});
// }, 200);
});
}
...
...
@@ -472,10 +566,15 @@ class FileManager {
};
const
task
=
this
.
tasks
.
new
(
LANG
[
'wget'
][
'task'
][
'name'
],
`
${
url
}
->
${
path
}
`
);
task
.
update
(
LANG
[
'wget'
][
'task'
][
'start'
]);
// http request
this
.
core
.
request
(
this
.
core
.
filemanager
.
wget
({
url
:
url
,
path
:
path
},
(
ret
)
=>
{
})
).
then
((
res
)
=>
{
let
ret
=
res
[
'text'
];
// 下载成功?当前目录?刷新:删除缓存
if
(
ret
===
'1'
)
{
task
.
success
(
LANG
[
'wget'
][
'task'
][
'success'
]);
...
...
@@ -484,7 +583,7 @@ class FileManager {
}
else
{
task
.
failed
(
LANG
[
'wget'
][
'task'
][
'failed'
](
ret
));
}
}
,
(
err
)
=>
{
}
).
catch
(
(
err
)
=>
{
task
.
failed
(
LANG
[
'wget'
][
'task'
][
'error'
](
err
));
});
layer
.
close
(
i
);
...
...
@@ -493,83 +592,109 @@ class FileManager {
$
(
`#layui-layer
${
_index
}
`
).
css
(
'width'
,
'400px'
);
}
// 上传文件
uploadFile
()
{
const
path
=
this
.
path
;
/**
* 上传文件
* @param {Array} _filePaths 要上传的本地文件路径(可选,如未指定,则调用文件选择框
* @return {None} [description]
*/
uploadFile
(
_filePaths
)
{
// 任务列表
let
tasks
=
{};
const
upload
=
(
filePaths
)
=>
{
if
(
!
filePaths
[
0
])
{
return
false
;
};
const
filePath
=
filePaths
[
0
];
let
i
=
0
;
// 上传路径
let
path
=
this
.
path
;
new
Promise
((
res
,
rej
)
=>
{
// 获取要上传的文件列表
if
(
Array
.
isArray
(
_filePaths
)
&&
_filePaths
.
length
>
0
)
{
return
res
(
_filePaths
);
}
dialog
.
showOpenDialog
({
properties
:
[
'openFile'
,
'multiSelections'
]
},
(
_filePaths
)
=>
{
if
(
!
_filePaths
)
{
return
};
return
res
(
_filePaths
);
})
}).
then
((
filePaths
)
=>
{
// 初始化任务
filePaths
.
map
((
f
)
=>
{
const
fileName
=
f
.
substr
(
f
.
lastIndexOf
(
'/'
)
+
1
);
tasks
[
f
]
=
this
.
tasks
.
new
(
LANG
[
'upload'
][
'task'
][
'name'
],
`
${
fileName
}
=>
${
path
}
`
,
'Waiting for uploading..'
);
});
return
filePaths
;
}).
then
((
filePaths
)
=>
{
// 文件上传(逐个队列上传
const
upload
=
()
=>
{
new
Promise
((
res
,
rej
)
=>
{
// 获取单个上传文件
let
filePath
=
filePaths
.
shift
();
if
(
filePath
)
{
res
(
filePath
);
}
}).
then
((
filePath
)
=>
{
// 上传单个
let
buffIndex
=
0
;
let
buff
=
[];
// 数据分段上传,一次上传512kb=1024*512
let
split
=
1024
*
512
;
cons
t
task
=
tasks
[
filePath
];
// 分段上传大小,默认1M
let
dataSplit
=
1024
*
1024
;
le
t
task
=
tasks
[
filePath
];
// 获取文件名
const
fileName
=
filePath
.
substr
(
filePath
.
lastIndexOf
(
'/'
)
+
1
);
let
fileName
=
filePath
.
substr
(
filePath
.
lastIndexOf
(
'/'
)
+
1
);
// 读取文件buff
let
fileBuff
;
// 读取文件buffer
try
{
try
{
fileBuff
=
fs
.
readFileSync
(
filePath
);
}
catch
(
e
)
{
}
catch
(
e
)
{
return
task
.
failed
(
e
);
}
while
(
true
)
{
const
_
=
fileBuff
.
slice
(
i
,
i
+
split
);
i
+=
split
;
if
(
_
.
length
===
0
)
{
break
};
buff
.
push
(
_
);
}
const
all_num
=
buff
.
length
;
const
upload_func
=
(
arr
)
=>
{
if
(
!
arr
[
0
])
{
// 文件数据分段
let
buffLength
=
fileBuff
.
length
;
while
(
buffIndex
<=
buffLength
)
{
let
buffSplit
=
fileBuff
.
slice
(
buffIndex
,
buffIndex
+
dataSplit
);
buffIndex
+=
dataSplit
;
buff
.
push
(
buffSplit
);
}
// 开始上传
const
uploadBuffFunc
=
(
_buff
)
=>
{
new
Promise
((
res
,
rej
)
=>
{
let
_b
=
_buff
.
shift
();
if
(
_b
)
{
res
(
_b
);
}
else
{
// 上传完毕
task
.
success
(
'100%'
);
// 刷新目录
toastr
.
success
(
LANG
[
'upload'
][
'success'
](
fileName
),
LANG_T
[
'success'
]);
// 刷新目录
缓存
// 刷新
缓存
this
.
files
.
refreshPath
(
path
===
this
.
path
?
''
:
path
);
return
upload
(
filePaths
);
};
// 继续上传
return
upload
();
}
}).
then
((
b
)
=>
{
// 更新进度条
task
.
update
(
`
${
parseInt
((
all_num
-
arr
.
length
)
/
all_num
*
100
)}
%`
);
// 开始上传分段数据
task
.
update
(
`
${
parseInt
((
buffLength
-
_buff
.
length
)
/
buffLength
*
100
)}
%`
);
this
.
core
.
request
(
this
.
core
.
filemanager
.
upload_file
({
path
:
path
+
fileName
,
content
:
arr
[
0
]
},
(
ret
)
=>
{
content
:
b
})
).
then
((
res
)
=>
{
let
ret
=
res
[
'text'
];
if
(
ret
===
'1'
)
{
// 继续上传
arr
.
shift
();
upload_func
(
arr
);
}
else
{
task
.
failed
(
LANG
[
'upload'
][
'task'
][
'failed'
](
ret
));
toastr
.
error
(
LANG
[
'upload'
][
'error'
](
fileName
,
ret
===
'0'
?
''
:
'<br/>'
+
ret
),
LANG_T
[
'error'
]);
return
uploadBuffFunc
(
_buff
);
}
},
(
err
)
=>
{
task
.
failed
(
LANG
[
'upload'
][
'task'
][
'failed'
](
ret
));
toastr
.
error
(
LANG
[
'upload'
][
'error'
](
fileName
,
ret
===
'0'
?
''
:
`<br/>
${
ret
}
`
),
LANG_T
[
'error'
]);
}).
catch
((
err
)
=>
{
task
.
failed
(
LANG
[
'upload'
][
'task'
][
'error'
](
err
));
toastr
.
error
(
LANG
[
'upload'
][
'error'
](
fileName
,
err
),
LANG_T
[
'error'
]);
});
})
}
upload_func
(
buff
);
filePaths
.
shift
();
}
dialog
.
showOpenDialog
({
properties
:
[
'openFile'
,
'multiSelections'
]
},
(
filePaths
)
=>
{
if
(
!
filePaths
)
{
return
};
// 逐个文件上传
filePaths
.
map
((
_
)
=>
{
const
fileName
=
_
.
substr
(
_
.
lastIndexOf
(
'/'
)
+
1
);
tasks
[
_
]
=
this
.
tasks
.
new
(
LANG
[
'upload'
][
'task'
][
'name'
],
`
${
fileName
}
=>
${
path
}
`
,
'准备上传..'
);
uploadBuffFunc
(
buff
);
});
upload
(
filePaths
);
};
upload
();
});
}
...
...
@@ -590,34 +715,13 @@ class FileManager {
// 检测文件后缀
let
ext
=
name
.
substr
(
name
.
lastIndexOf
(
'.'
)
+
1
);
let
ext_dict
=
{
'php'
:
'php'
,
'c'
:
'c_cpp'
,
'cpp'
:
'c_cpp'
,
'h'
:
'c_cpp'
,
'coffee'
:
'coffee'
,
'cfm'
:
'coldfusion'
,
'css'
:
'css'
,
// 'ejs': 'ejs',
'go'
:
'golang'
,
'html'
:
'html'
,
'ini'
:
'ini'
,
'conf'
:
'ini'
,
'jade'
:
'jade'
,
'java'
:
'java'
,
'js'
:
'javascript'
,
'json'
:
'json'
,
'jsp'
:
'jsp'
,
'jsx'
:
'jsx'
,
'less'
:
'less'
,
'lua'
:
'lua'
,
'md'
:
'markdown'
,
'sql'
:
'sql'
,
'pl'
:
'perl'
,
'py'
:
'python'
,
'rb'
:
'ruby'
,
'sh'
:
'sh'
,
'txt'
:
'text'
,
'xml'
:
'xml'
'php'
:
'php'
,
'c'
:
'c_cpp'
,
'cpp'
:
'c_cpp'
,
'h'
:
'c_cpp'
,
'coffee'
:
'coffee'
,
'cfm'
:
'coldfusion'
,
'css'
:
'css'
,
'go'
:
'golang'
,
'html'
:
'html'
,
'ini'
:
'ini'
,
'conf'
:
'ini'
,
'jade'
:
'jade'
,
'java'
:
'java'
,
'js'
:
'javascript'
,
'json'
:
'json'
,
'jsp'
:
'jsp'
,
'jsx'
:
'jsx'
,
'less'
:
'less'
,
'lua'
:
'lua'
,
'md'
:
'markdown'
,
'sql'
:
'sql'
,
'pl'
:
'perl'
,
'py'
:
'python'
,
'rb'
:
'ruby'
,
'sh'
:
'sh'
,
'txt'
:
'text'
,
'xml'
:
'xml'
}
if
(
!
(
ext
in
ext_dict
))
{
ext
=
'txt'
};
// 创建窗口工具栏
...
...
@@ -665,11 +769,13 @@ class FileManager {
if
(
id
===
'save'
)
{
// 保存代码
win
.
progressOn
();
// self.ajax
(
self
.
core
.
request
(
self
.
core
.
filemanager
.
create_file
({
path
:
path
,
content
:
editor
.
session
.
getValue
()
||
'
\
0'
},
(
ret
)
=>
{
content
:
editor
.
session
.
getValue
()
||
'Halo ANT!'
})
).
then
((
res
)
=>
{
let
ret
=
res
[
'text'
];
win
.
progressOff
();
if
(
ret
===
'1'
)
{
toastr
.
success
(
LANG
[
'editor'
][
'success'
](
path
),
LANG_T
[
'success'
]);
...
...
@@ -678,8 +784,9 @@ class FileManager {
}
else
{
toastr
.
error
(
LANG
[
'editor'
][
'error'
](
path
,
ret
===
'0'
?
''
:
'<br/>'
+
ret
),
LANG_T
[
'error'
]);
}
}
)
}).
catch
((
err
)
=>
{
});
}
else
if
(
id
.
startsWith
(
'mode_'
))
{
let
mode
=
id
.
split
(
'_'
)[
1
];
editor
.
session
.
setMode
(
`ace/mode/
${
mode
}
`
);
...
...
@@ -692,9 +799,12 @@ class FileManager {
});
// 获取文件代码
this
.
core
.
request
(
this
.
core
.
filemanager
.
read_file
({
path
:
path
},
(
ret
)
=>
{
})
).
then
((
res
)
=>
{
let
ret
=
res
[
'text'
];
codes
=
ret
;
win
.
progressOff
();
...
...
@@ -732,7 +842,7 @@ class FileManager {
clearInterval
(
inter
);
return
true
;
});
}
,
(
err
)
=>
{
}
).
catch
(
(
err
)
=>
{
toastr
.
error
(
LANG
[
'editor'
][
'loadErr'
](
err
),
LANG_T
[
'error'
]);
win
.
close
();
});
...
...
source/modules/terminal/index.jsx
View file @
9a0fbbd7
//
// 虚拟终端模块
//
/**
* 虚拟终端模块
* 更新:2016/04/13
* 作者:蚁逅 <https://github.com/antoor>
*/
// import React from 'react';
// import ReactDOM from 'react-dom';
const
LANG_T
=
antSword
[
'language'
][
'toastr'
];
const
LANG
=
antSword
[
'language'
][
'terminal'
];
// const ipcRenderer = antSword['ipcRendere
r'];
const
LANG_T
=
antSword
[
'language'
][
'toast
r'
];
class
Terminal
{
constructor
(
opts
)
{
const
tabbar
=
antSword
[
'tabbar'
];
// 生存一个随机ID,用于标识多个窗口dom
const
hash
=
String
(
Math
.
random
()).
substr
(
2
,
10
);
// 初始化UI::tabbar
const
tabbar
=
antSword
[
'tabbar'
];
tabbar
.
addTab
(
`tab_terminal_
${
hash
}
`
,
// `<i class="fa fa-terminal"></i> ${LANG['title']} \/\/ ${opts['ip']}`,
`<i class="fa fa-terminal"></i>
${
opts
[
'ip'
]}
`
,
null
,
null
,
true
,
true
);
tabbar
.
attachEvent
(
'onTabClick'
,
(
id
,
lid
)
=>
{
if
(
id
===
`tab_terminal_
${
hash
}
`
)
{
if
(
id
!==
`tab_terminal_
${
hash
}
`
)
{
return
};
this
.
term
?
this
.
term
.
focus
()
:
0
;
};
});
// 初始化UI::cell
const
cell
=
tabbar
.
cells
(
`tab_terminal_
${
hash
}
`
);
// ReactDOM.render(
// <div id={`div_terminal_${hash}`} style={{
// height: '100%',
// margin: '0',
// padding: '0px 5px 1px 5px',
// overflow: 'scroll'
// }} />
// , cell.cell
// );
cell
.
attachHTMLString
(
`
<div id="div_terminal_
${
hash
}
" style="height:100%;margin:0;padding:0 5px 1px 5px;overflow:scroll"></div>
<div
id="div_terminal_
${
hash
}
"
style="height:100%;margin:0;padding:0 5px 1px 5px;overflow:scroll"
></div>
`
);
this
.
path
=
''
;
...
...
@@ -48,84 +40,95 @@ class Terminal {
this
.
cell
=
cell
;
this
.
isWin
=
true
;
this
.
core
=
new
antSword
[
'core'
][
opts
[
'type'
]](
opts
);
this
.
cache
=
new
antSword
[
'CacheManager'
](
this
.
opts
[
'_id'
]);
// this.initTerminal($(`#div_terminal_${hash}`));
// 获取缓存::info
const
dom
=
$
(
`#div_terminal_
${
hash
}
`
);
const
cache_info
=
this
.
cache
.
get
(
'info'
);
if
(
cache_info
)
{
this
.
initTerminal
(
cache_info
,
dom
);
}
else
{
this
.
cell
.
progressOn
();
this
.
core
.
base
.
info
((
ret
)
=>
{
this
.
cell
.
progressOff
();
// 判断获取数据是否正确
// let info = ret.split('\t');
// if (info.length !== 4) {
// toastr.error('Loading infomations failed!', LANG_T['error']);
// return this.cell.close();
// };
// 更新缓存
this
.
cache
.
set
(
'info'
,
ret
);
// ipcRenderer.sendSync('cache-add', {
// id: this.opts['id'],
// tag: 'info',
// cache: ret
// });
// 初始化终端
this
.
initTerminal
(
ret
,
dom
);
},
(
err
)
=>
{
this
.
getInformation
()
.
then
((
ret
)
=>
{
this
.
initTerminal
(
ret
[
'info'
],
ret
[
'dom'
]);
})
.
catch
((
err
)
=>
{
toastr
.
error
((
typeof
(
err
)
===
'object'
)
?
JSON
.
stringify
(
err
)
:
String
(
err
),
LANG_T
[
'error'
]);
this
.
cell
.
progressOff
();
this
.
cell
.
close
();
})
}
/**
* 获取目标信息
* @return {Promise} 返回一个Promise操作对象//{dom,info}
*/
getInformation
()
{
return
new
Promise
((
ret
,
rej
)
=>
{
// 获取DOM
const
dom
=
$
(
`#div_terminal_
${
this
.
hash
}
`
);
// 获取缓存
let
infoCache
=
this
.
cache
.
get
(
'info'
);
// 如果有缓存?初始化终端:获取信息&&保存缓存&&初始化终端
if
(
infoCache
)
{
return
ret
({
dom
:
dom
,
info
:
infoCache
});
}
// 开始获取信息
this
.
cell
.
progressOn
();
this
.
core
.
request
(
this
.
core
.
base
.
info
()
).
then
((
_ret
)
=>
{
this
.
cell
.
progressOff
();
this
.
cache
.
set
(
'info'
,
_ret
[
'text'
]);
return
ret
({
dom
:
dom
,
info
:
_ret
[
'text'
]
});
}).
catch
((
e
)
=>
{
rej
(
e
);
});
});
}
// 初始化终端
/**
* 初始化终端
* @param {String} ret 目标信息
* @param {Object} dom 要操作的dom元素
* @return {None} [description]
*/
initTerminal
(
ret
,
dom
)
{
// this.cell.progressOn();
// // 获取缓存info
// const _info = ipcRenderer.sendSync('cache-get', {
// id: this.opts['id'],
// tag: 'info'
// });
// this.core.base.info((ret) => {
// this.cell.progressOff();
let
info
=
ret
.
split
(
'
\
t'
);
let
info_user
;
let
info_path
;
let
info_drive
;
let
info_system
;
// 解析banner
let
infoUser
,
infoPath
,
infoDrive
,
infoSystem
;
let
banner
=
`[[b;cyan;](*)
${
LANG
[
'banner'
][
'title'
]}
]`
;
// 判断获取数据是否正确
// 判断数据是否正确
if
(
info
.
length
===
4
)
{
info_user
=
info
[
3
];
info_path
=
info
[
0
];
info_drive
=
info
[
1
];
info_system
=
info
[
2
];
}
else
if
(
info
.
length
===
2
)
{
info_p
ath
=
info
[
0
];
info_d
rive
=
info
[
1
];
}
else
{
infoPath
=
info
[
0
];
infoDrive
=
info
[
1
];
infoSystem
=
info
[
2
];
infoUser
=
info
[
3
];
}
else
if
(
info
.
length
===
2
)
{
infoP
ath
=
info
[
0
];
infoD
rive
=
info
[
1
];
}
else
{
toastr
.
error
(
'Loading infomations failed!<br/>'
+
ret
,
LANG_T
[
'error'
]);
this
.
cache
.
del
(
'info'
);
return
this
.
cell
.
close
();
};
info_path
=
info_path
.
replace
(
/
\\
/g
,
'/'
).
replace
(
/
\.
$/
,
''
);
// 判断是否为linux
if
(
info_path
.
substr
(
0
,
1
)
===
'/'
)
{
this
.
isWin
=
false
;
};
this
.
path
=
info_path
;
banner
+=
`\n[[b;#99A50D;]
${
LANG
[
'banner'
][
'path'
]}
]: [[;#C3C3C3;]
${
info_path
}
]`
;
banner
+=
`\n[[b;#99A50D;]
${
LANG
[
'banner'
][
'drive'
]}
]: [[;#C3C3C3;]
${
info_drive
}
]`
;
}
// 转换路径特殊字符
infoPath
=
infoPath
.
replace
(
/
\\
/g
,
'/'
).
replace
(
/
\.
$/
,
''
);
// 判断是否为!win
this
.
isWin
=
!
(
infoPath
.
substr
(
0
,
1
)
===
'/'
)
this
.
path
=
infoPath
;
// 组合banner
banner
+=
`\n[[b;#99A50D;]
${
LANG
[
'banner'
][
'path'
]}
]: [[;#C3C3C3;]
${
infoPath
}
]`
;
banner
+=
`\n[[b;#99A50D;]
${
LANG
[
'banner'
][
'drive'
]}
]: [[;#C3C3C3;]
${
infoDrive
}
]`
;
if
(
info
.
length
===
4
)
{
banner
+=
`\n[[b;#99A50D;]
${
LANG
[
'banner'
][
'system'
]}
]: [[;#C3C3C3;]
${
info_s
ystem
}
]`
;
banner
+=
`\n[[b;#99A50D;]
${
LANG
[
'banner'
][
'user'
]}
]: [[;#C3C3C3;]
${
info_u
ser
}
]`
;
banner
+=
`\n[[b;#99A50D;]
${
LANG
[
'banner'
][
'system'
]}
]: [[;#C3C3C3;]
${
infoS
ystem
}
]`
;
banner
+=
`\n[[b;#99A50D;]
${
LANG
[
'banner'
][
'user'
]}
]: [[;#C3C3C3;]
${
infoU
ser
}
]`
;
}
// 初始化终端
this
.
term
=
dom
.
terminal
(
(
cmd
,
term
)
=>
{
if
(
!
cmd
)
{
return
false
};
...
...
@@ -133,73 +136,89 @@ class Terminal {
if
(
cmd
===
'exit'
||
cmd
===
'quit'
)
{
return
this
.
cell
.
close
()
};
term
.
pause
();
// 是否有缓存
let
cache_tag
=
'command-'
+
new
Buffer
(
this
.
path
+
cmd
).
toString
(
'base64'
);
let
cache_cmd
;
if
(
cache_cmd
=
this
.
cache
.
get
(
cache_tag
))
{
term
.
echo
(
antSword
.
noxss
(
cache_cmd
));
let
cacheTag
=
'command-'
+
new
Buffer
(
this
.
path
+
cmd
).
toString
(
'base64'
);
let
cacheCmd
;
if
(
cacheCmd
=
this
.
cache
.
get
(
cacheTag
))
{
term
.
echo
(
antSword
.
noxss
(
cacheCmd
)
);
return
term
.
resume
();
};
// 开始执行命令
this
.
core
.
request
(
this
.
core
.
command
.
exec
({
cmd
:
this
.
parseCmd
(
cmd
,
this
.
path
),
bin
:
this
.
isWin
?
'cmd'
:
'/bin/sh'
},
(
_
)
=>
{
})
).
then
((
ret
)
=>
{
let
_
=
ret
[
'text'
];
// 解析出命令执行路径
const
index_s
=
_
.
indexOf
(
'[S]'
);
const
index_e
=
_
.
lastIndexOf
(
'[E]'
);
let
_path
=
_
.
substr
(
index_s
+
3
,
index_e
-
index_s
-
3
);
const
indexS
=
_
.
indexOf
(
'[S]'
);
const
indexE
=
_
.
lastIndexOf
(
'[E]'
);
let
_path
=
_
.
substr
(
indexS
+
3
,
indexE
-
indexS
-
3
);
// let _sindex = _.indexOf('[S]') + 3;
// let _eindex = _.indexOf('[E]');
// let _path = _.substr(_sindex, _eindex - _sindex);
let
output
=
_
.
replace
(
`[S]
${
_path
}
[E]`
,
''
);
_path
=
_path
.
replace
(
/
\n
/g
,
''
).
replace
(
/
\r
/g
,
''
);
this
.
path
=
_path
||
this
.
path
;
term
.
set_prompt
(
this
.
parsePrompt
(
info_u
ser
));
term
.
set_prompt
(
this
.
parsePrompt
(
infoU
ser
));
// let output = _.substr(0, _sindex - 3).replace(/\n$/, '');
// 去除换行符
[
/
\n\n
$/
,
/^
\n\n
/
,
/
\r\r
$/
,
/^
\r\r
/
,
/
\r\n
$/
,
/^
\r\n
/
,
/
\n\r
$/
,
/^
\n\r
/
,
/
\r
$/
,
/^
\r
/
,
/
\n
$/
,
/^
\n
/
].
map
((
_
)
=>
{
[
/
\n\n
$/
,
/^
\n\n
/
,
/
\r\r
$/
,
/^
\r\r
/
,
/
\r\n
$/
,
/^
\r\n
/
,
/
\n\r
$/
,
/^
\n\r
/
,
/
\r
$/
,
/^
\r
/
,
/
\n
$/
,
/^
\n
/
].
map
((
_
)
=>
{
output
=
output
.
replace
(
_
,
''
);
});
// output = output.replace(/\n$/, '').replace(/^\n/, '').replace(/^\r/, '').replace(/\r$/, '').;
if
(
output
.
length
>
0
)
{
term
.
echo
(
antSword
.
noxss
(
output
));
term
.
echo
(
antSword
.
noxss
(
output
)
);
// 保存最大100kb数据
if
(
output
.
length
<
(
1024
*
1024
))
{
this
.
cache
.
set
(
cache_t
ag
,
output
);
this
.
cache
.
set
(
cacheT
ag
,
output
);
};
};
term
.
resume
();
},
(
_
)
=>
{
}).
catch
((
e
)
=>
{
term
.
error
(
'ERR: '
+
(
_
instanceof
Object
)
?
JSON
.
stringify
(
_
)
:
String
(
_
));
term
.
resume
();
}
)
});
},
{
greetings
:
banner
,
name
:
`terminal_
${
this
.
hash
}
`
,
prompt
:
this
.
parsePrompt
(
info_u
ser
),
prompt
:
this
.
parsePrompt
(
infoU
ser
),
exit
:
false
});
// }, (err) => {
// toastr.error(err, LANG_T['error']);
// this.cell.progressOff();
// this.cell.close();
// });
}
// 生成CMD代码
/**
* 根据执行命令&&路径生成最终command
* @param {String} cmd 要执行的命令
* @param {String} path 当前路径
* @return {String} 最终执行命令
*/
parseCmd
(
cmd
,
path
)
{
path
=
path
.
replace
(
/
\\\\
/g
,
'
\
\'
).replace(/"/g, '
\\
"').replace(/
\\
/g, '
\\\\
');
return this.isWin ? `cd /d "
$
{
path
}
"&${cmd}&echo [S]&cd&echo [E]` : `cd "
$
{
path
}
";${cmd};echo [S];pwd;echo [E]`;
return (this.isWin
? `cd /d "
$
{
path
}
"&${cmd}&echo [S]&cd&echo [E]`
: `cd "
$
{
path
}
";${cmd};echo [S];pwd;echo [E]`
);
}
// 生成路径提示
/**
* 生成路径提示符
* @param {String} user 当前用户名
* @return {String} term输出字符串
*/
parsePrompt(user) {
let ret = this.isWin ? '[[b;white;]' + this.path.replace(/
\
//g, '
\\
') + '> ]' : (user ? ('([[b;#E80000;]' + user + ']:[[;#0F93D2;]') : '[[;0F93D2;]') + this.path + ']) $ ';
return antSword.noxss(ret);
return antSword.noxss(this.isWin
? `[[b;white;]${this.path.replace(/
\
//g, '
\\
')}> ]`
: (user ? `([[b;#E80000;]${user}]:[[;#0F93D2;]` : '[[;0F93D2;]') + this.path + ']) $ '
);
}
}
...
...
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