Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
L
luna
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
luna
Commits
5727afd9
Commit
5727afd9
authored
Sep 27, 2017
by
i317280
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
823c76b0
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
77 additions
and
81 deletions
+77
-81
terminal.html
src/app/TerminalPage/terminal.html
+3
-3
terminal.ts
src/app/TerminalPage/terminal.ts
+74
-51
app.service.ts
src/app/app.service.ts
+0
-27
No files found.
src/app/TerminalPage/terminal.html
View file @
5727afd9
<div
id=
"tabs"
>
<ul>
<li
*
ngFor=
"let m of
Data
Store.term;let i = index"
[
ngClass
]="{'
active
'
:i=
=
Data
Store.termActive,'disconnected':!m.connected,
'
hidden
'
:
m
.
closed
!=
false
}"
<li
*
ngFor=
"let m of
Term
Store.term;let i = index"
[
ngClass
]="{'
active
'
:i=
=
Term
Store.termActive,'disconnected':!m.connected,
'
hidden
'
:
m
.
closed
!=
false
}"
id=
"termnav-{{i}}"
(
click
)="
setActive
(
i
)"
>
<span
*
ngIf=
"!m.edit"
(
dblclick
)="
m
.
edit=
true;setActive(i)"
>
{{m.nick}}
</span>
<input
*
ngIf=
"m.edit"
[(
ngModel
)]="
m
.
nick
"
autofocus
(
blur
)="
m
.
edit=
false"
(
keyup
.
enter
)="
m
.
edit=
false"/
>
...
...
@@ -13,7 +13,7 @@
<!--<div-->
<!--[ngClass]="{'disconnected':!DataStore.term[0].connected, 'hidden': i!=DataStore.termActive || DataStore.term[0].closed}"-->
<!--id="term-0"></div>-->
<div
*
ngFor=
"let m of
Data
Store.term;let i=index"
<div
*
ngFor=
"let m of
Term
Store.term;let i=index"
[
ngClass
]="{'
disconnected
'
:
!
m
.
connected
,'
hidden
'
:
m
.
hide
}"
id=
"term-{{i}}"
>
</div>
</div>
...
...
src/app/TerminalPage/terminal.ts
View file @
5727afd9
...
...
@@ -6,8 +6,30 @@ import {Cookie} from 'ng2-cookies/ng2-cookies';
declare
let
jQuery
:
any
;
declare
let
Terminal
:
any
;
import
{
AppService
,
DataStore
,
Term
}
from
'../app.service'
;
import
{
AppService
,
DataStore
}
from
'../app.service'
;
export
class
Term
{
nick
:
string
;
edit
:
boolean
;
machine
:
string
;
connected
:
boolean
;
closed
:
boolean
;
socket
:
any
;
term
:
any
;
hide
:
boolean
;
}
export
let
TermStore
:
{
term
:
Array
<
Term
>
;
termlist
:
Array
<
string
>
;
termActive
:
number
;
}
=
{
term
:
[
new
Term
()],
termlist
:
[],
termActive
:
0
,
};
@
Component
({
selector
:
'term-body'
,
...
...
@@ -19,6 +41,7 @@ import {AppService, DataStore, Term} from '../app.service';
export
class
TerminalComponent
implements
OnInit
{
DataStore
=
DataStore
;
TermStore
=
TermStore
;
constructor
(
private
_appService
:
AppService
,
private
_logger
:
Logger
)
{
...
...
@@ -26,7 +49,7 @@ export class TerminalComponent implements OnInit {
}
ngOnInit
()
{
//
Data
Store.term[0]["term"].open(document.getElementById("term-0"))
//
Term
Store.term[0]["term"].open(document.getElementById("term-0"))
this
.
timer
();
}
...
...
@@ -37,11 +60,11 @@ export class TerminalComponent implements OnInit {
}
timer
()
{
if
(
Data
Store
.
termlist
.
length
>
0
)
{
for
(
let
i
in
Data
Store
.
termlist
)
{
this
.
TerminalConnect
(
Data
Store
.
termlist
[
i
]);
if
(
Term
Store
.
termlist
.
length
>
0
)
{
for
(
let
i
in
Term
Store
.
termlist
)
{
this
.
TerminalConnect
(
Term
Store
.
termlist
[
i
]);
}
Data
Store
.
termlist
=
[]
Term
Store
.
termlist
=
[]
}
jQuery
(
window
).
trigger
(
'resize'
);
setTimeout
(()
=>
{
...
...
@@ -52,39 +75,39 @@ export class TerminalComponent implements OnInit {
close
(
i
)
{
this
.
_logger
.
debug
(
i
);
TerminalComponent
.
TerminalDisconnect
(
i
);
Data
Store
.
term
[
i
].
hide
=
true
;
Data
Store
.
term
[
i
].
closed
=
true
;
Data
Store
.
term
[
i
].
term
.
destroy
();
Data
Store
.
term
.
splice
(
i
,
1
);
Term
Store
.
term
[
i
].
hide
=
true
;
Term
Store
.
term
[
i
].
closed
=
true
;
Term
Store
.
term
[
i
].
term
.
destroy
();
Term
Store
.
term
.
splice
(
i
,
1
);
TerminalComponent
.
checkActive
(
i
);
}
static
checkActive
(
index
)
{
let
len
=
Data
Store
.
term
.
length
;
let
len
=
Term
Store
.
term
.
length
;
if
(
len
==
1
)
{
// 唯一一个
Data
Store
.
termActive
=
0
;
Term
Store
.
termActive
=
0
;
}
else
if
(
len
-
1
==
index
)
{
// 删了最后一个
Data
Store
.
termActive
=
len
-
2
;
Term
Store
.
termActive
=
len
-
2
;
}
else
{
Data
Store
.
termActive
=
index
;
Term
Store
.
termActive
=
index
;
}
TerminalComponent
.
setActive
(
Data
Store
.
termActive
)
TerminalComponent
.
setActive
(
Term
Store
.
termActive
)
}
setActive
=
TerminalComponent
.
setActive
;
static
setActive
(
index
)
{
for
(
let
m
in
Data
Store
.
term
)
{
Data
Store
.
term
[
m
].
hide
=
true
;
for
(
let
m
in
Term
Store
.
term
)
{
Term
Store
.
term
[
m
].
hide
=
true
;
}
Data
Store
.
term
[
index
].
hide
=
false
;
Data
Store
.
termActive
=
index
;
Term
Store
.
term
[
index
].
hide
=
false
;
Term
Store
.
termActive
=
index
;
}
dblclick
()
{
console
.
log
(
Data
Store
.
term
)
console
.
log
(
Term
Store
.
term
)
}
TerminalConnect
(
uuid
)
{
...
...
@@ -101,52 +124,52 @@ export class TerminalComponent implements OnInit {
Cookie
.
set
(
'rows'
,
rows
,
99
,
'/'
,
document
.
domain
);
let
id
=
Data
Store
.
term
.
length
-
1
;
Data
Store
.
term
[
id
].
machine
=
'localhost'
;
Data
Store
.
term
[
id
].
nick
=
'localhost'
;
Data
Store
.
term
[
id
].
connected
=
true
;
Data
Store
.
term
[
id
].
socket
=
socket
;
Data
Store
.
term
[
id
].
edit
=
false
;
Data
Store
.
term
[
id
].
closed
=
false
;
Data
Store
.
term
[
id
].
term
=
new
Terminal
({
let
id
=
Term
Store
.
term
.
length
-
1
;
Term
Store
.
term
[
id
].
machine
=
'localhost'
;
Term
Store
.
term
[
id
].
nick
=
'localhost'
;
Term
Store
.
term
[
id
].
connected
=
true
;
Term
Store
.
term
[
id
].
socket
=
socket
;
Term
Store
.
term
[
id
].
edit
=
false
;
Term
Store
.
term
[
id
].
closed
=
false
;
Term
Store
.
term
[
id
].
term
=
new
Terminal
({
cols
:
cols
,
rows
:
rows
,
useStyle
:
true
,
screenKeys
:
true
,
});
Data
Store
.
term
.
push
(
new
Term
());
for
(
let
m
in
Data
Store
.
term
)
{
Data
Store
.
term
[
m
].
hide
=
true
;
Term
Store
.
term
.
push
(
new
Term
());
for
(
let
m
in
Term
Store
.
term
)
{
Term
Store
.
term
[
m
].
hide
=
true
;
}
Data
Store
.
term
[
id
].
hide
=
false
;
Term
Store
.
term
[
id
].
hide
=
false
;
Data
Store
.
termActive
=
id
;
Term
Store
.
termActive
=
id
;
//
Data
Store.term[id]['term'].on('title', function (title) {
//
Term
Store.term[id]['term'].on('title', function (title) {
// document.title = title;
// });
DataStore
.
term
[
id
].
term
.
open
(
document
.
getElementById
(
'term-'
+
id
)
);
TermStore
.
term
[
id
].
term
.
open
(
document
.
getElementById
(
'term-'
+
id
),
true
);
Data
Store
.
term
[
id
].
term
.
write
(
'
\
x1b[31mWelcome to Jumpserver!
\
x1b[m
\
r
\
n'
);
Term
Store
.
term
[
id
].
term
.
write
(
'
\
x1b[31mWelcome to Jumpserver!
\
x1b[m
\
r
\
n'
);
socket
.
on
(
'connect'
,
function
()
{
socket
.
emit
(
'machine'
,
uuid
);
Data
Store
.
term
[
id
].
term
.
on
(
'data'
,
function
(
data
)
{
Term
Store
.
term
[
id
].
term
.
on
(
'data'
,
function
(
data
)
{
socket
.
emit
(
'data'
,
data
);
});
socket
.
on
(
'data'
,
function
(
data
)
{
Data
Store
.
term
[
id
].
term
.
write
(
data
);
Term
Store
.
term
[
id
].
term
.
write
(
data
);
});
socket
.
on
(
'disconnect'
,
function
()
{
this
.
TerminalDisconnect
(
id
);
//
Data
Store.term[id]["term"].destroy();
//
Data
Store.term[id]["connected"] = false;
//
Term
Store.term[id]["term"].destroy();
//
Term
Store.term[id]["connected"] = false;
});
window
.
onresize
=
function
()
{
...
...
@@ -165,10 +188,10 @@ export class TerminalComponent implements OnInit {
if
(
row
<
24
)
row
=
24
;
if
(
cols
==
col
&&
row
==
rows
)
{
}
else
{
for
(
let
tid
in
Data
Store
.
term
)
{
if
(
Data
Store
.
term
[
tid
].
connected
)
{
Data
Store
.
term
[
tid
].
socket
.
emit
(
'resize'
,
[
col
,
row
]);
Data
Store
.
term
[
tid
].
term
.
resize
(
col
,
row
);
for
(
let
tid
in
Term
Store
.
term
)
{
if
(
Term
Store
.
term
[
tid
].
connected
)
{
Term
Store
.
term
[
tid
].
socket
.
emit
(
'resize'
,
[
col
,
row
]);
Term
Store
.
term
[
tid
].
term
.
resize
(
col
,
row
);
}
}
Cookie
.
set
(
'cols'
,
String
(
col
),
99
,
'/'
,
document
.
domain
);
...
...
@@ -180,18 +203,18 @@ export class TerminalComponent implements OnInit {
}
static
TerminalDisconnect
(
i
)
{
Data
Store
.
term
[
i
].
connected
=
false
;
Data
Store
.
term
[
i
].
socket
.
destroy
();
Data
Store
.
term
[
i
].
term
.
write
(
'
\
r
\
n
\
x1b[31mBye Bye!
\
x1b[m
\
r
\
n'
);
Term
Store
.
term
[
i
].
connected
=
false
;
Term
Store
.
term
[
i
].
socket
.
destroy
();
Term
Store
.
term
[
i
].
term
.
write
(
'
\
r
\
n
\
x1b[31mBye Bye!
\
x1b[m
\
r
\
n'
);
}
static
TerminalDisconnectAll
()
{
alert
(
"TerminalDisconnectAll"
);
for
(
let
i
in
Data
Store
.
term
)
{
for
(
let
i
in
Term
Store
.
term
)
{
TerminalComponent
.
TerminalDisconnect
(
i
);
//
Data
Store.term[i]["connected"] = false;
//
Data
Store.term[i]["socket"].destroy();
//
Data
Store.term[i]["term"].write('\r\n\x1b[31mBye Bye!\x1b[m\r\n');
//
Term
Store.term[i]["connected"] = false;
//
Term
Store.term[i]["socket"].destroy();
//
Term
Store.term[i]["term"].write('\r\n\x1b[31mBye Bye!\x1b[m\r\n');
}
}
}
src/app/app.service.ts
View file @
5727afd9
...
...
@@ -74,50 +74,23 @@ export let User: {
logined
:
false
,
};
export
class
Term
{
nick
:
string
;
edit
:
boolean
;
machine
:
string
;
connected
:
boolean
;
closed
:
boolean
;
socket
:
any
;
term
:
any
;
hide
:
boolean
;
}
export
let
DataStore
:
{
socket
:
any
;
Nav
:
Array
<
{}
>
;
lastNavigationAttempt
:
string
;
route
:
Array
<
{}
>
;
activenav
:
{};
Path
:
{};
error
:
{};
msg
:
{};
leftbar
:
string
;
leftbarrightclick
:
string
;
loglevel
:
number
;
term
:
Array
<
Term
>
;
termActive
:
number
;
leftbarhide
:
boolean
;
termlist
:
Array
<
string
>
;
windowsize
:
Array
<
number
>
;
}
=
{
socket
:
io
.
connect
(),
Nav
:
[{}],
lastNavigationAttempt
:
''
,
route
:
[{}],
activenav
:
{},
Path
:
{},
error
:
{},
msg
:
{},
leftbar
:
'/api/leftbar'
,
leftbarrightclick
:
'/api/leftbarrightclick'
,
loglevel
:
0
,
term
:
[
new
Term
()],
termActive
:
0
,
leftbarhide
:
false
,
termlist
:
[],
windowsize
:
[],
};
...
...
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