Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
webssh
Overview
Overview
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
郑天保
webssh
Commits
2c36c386
Commit
2c36c386
authored
May 26, 2018
by
Sheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
jslint compliant
parent
cce93716
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
69 additions
and
56 deletions
+69
-56
main.js
webssh/static/js/main.js
+69
-56
No files found.
webssh/static/js/main.js
View file @
2c36c386
var
jQuery
;
var
wssh
=
{};
jQuery
(
function
(
$
){
jQuery
(
function
(
$
){
/*jslint browser:true */
var
status
=
$
(
'#status'
),
var
status
=
$
(
'#status'
),
btn
=
$
(
'.btn-primary'
),
btn
=
$
(
'.btn-primary'
),
style
=
{};
style
=
{};
$
(
'form#connect'
).
submit
(
function
(
event
)
{
event
.
preventDefault
();
var
form
=
$
(
this
),
url
=
form
.
attr
(
'action'
),
type
=
form
.
attr
(
'type'
),
data
=
new
FormData
(
this
);
if
(
!
data
.
get
(
'hostname'
)
||
!
data
.
get
(
'port'
)
||
!
data
.
get
(
'username'
))
{
status
.
text
(
'Hostname, port and username are required.'
);
return
;
}
var
pk
=
data
.
get
(
'privatekey'
);
if
(
pk
&&
pk
.
size
>
16384
)
{
status
.
text
(
'Key size exceeds maximum value.'
);
return
;
}
status
.
text
(
''
);
btn
.
prop
(
'disabled'
,
true
);
$
.
ajax
({
url
:
url
,
type
:
type
,
data
:
data
,
success
:
callback
,
cache
:
false
,
contentType
:
false
,
processData
:
false
});
});
function
parse_xterm_style
()
{
function
parse_xterm_style
()
{
var
text
=
$
(
'.xterm-helpers style'
).
text
();
var
text
=
$
(
'.xterm-helpers style'
).
text
();
...
@@ -52,22 +23,24 @@ jQuery(function($){
...
@@ -52,22 +23,24 @@ jQuery(function($){
if
(
!
style
.
width
||
!
style
.
height
)
{
if
(
!
style
.
width
||
!
style
.
height
)
{
parse_xterm_style
();
parse_xterm_style
();
}
}
cols
=
parseInt
(
window
.
innerWidth
/
style
.
width
)
-
1
;
rows
=
parseInt
(
window
.
innerHeight
/
style
.
height
);
var
cols
=
parseInt
(
window
.
innerWidth
/
style
.
width
,
10
)
-
1
;
var
rows
=
parseInt
(
window
.
innerHeight
/
style
.
height
,
10
);
return
{
'cols'
:
cols
,
'rows'
:
rows
};
return
{
'cols'
:
cols
,
'rows'
:
rows
};
}
}
function
resize_term
(
term
,
sock
et
)
{
function
resize_term
(
term
,
sock
)
{
var
geometry
=
current_geometry
(),
var
geometry
=
current_geometry
(),
cols
=
geometry
.
cols
,
cols
=
geometry
.
cols
,
rows
=
geometry
.
rows
;
rows
=
geometry
.
rows
;
// console.log([cols, rows]);
// console.log([cols, rows]);
// console.log(term.geometry);
// console.log(term.geometry);
if
(
cols
!=
term
.
geometry
[
0
]
||
rows
!=
term
.
geometry
[
1
])
{
if
(
cols
!==
term
.
geometry
[
0
]
||
rows
!==
term
.
geometry
[
1
])
{
console
.
log
(
'resizing term'
);
console
.
log
(
'resizing term'
);
term
.
resize
(
cols
,
rows
);
term
.
resize
(
cols
,
rows
);
sock
et
.
send
(
JSON
.
stringify
({
'resize'
:
[
cols
,
rows
]}));
sock
.
send
(
JSON
.
stringify
({
'resize'
:
[
cols
,
rows
]}));
}
}
}
}
...
@@ -83,50 +56,55 @@ jQuery(function($){
...
@@ -83,50 +56,55 @@ jQuery(function($){
}
}
var
ws_url
=
window
.
location
.
href
.
replace
(
'http'
,
'ws'
),
var
ws_url
=
window
.
location
.
href
.
replace
(
'http'
,
'ws'
),
join
=
(
ws_url
[
ws_url
.
length
-
1
]
==
'/'
?
''
:
'/'
),
join
=
(
ws_url
[
ws_url
.
length
-
1
]
==
=
'/'
?
''
:
'/'
),
url
=
ws_url
+
join
+
'ws?id='
+
msg
.
id
,
url
=
ws_url
+
join
+
'ws?id='
+
msg
.
id
,
terminal
=
document
.
getElementById
(
'#terminal'
);
sock
=
new
window
.
WebSocket
(
url
),
socket
=
new
WebSocket
(
url
);
terminal
=
document
.
getElementById
(
'#terminal'
),
term
=
new
Terminal
({
term
=
new
window
.
Terminal
({
cursorBlink
:
true
,
cursorBlink
:
true
,
});
});
console
.
log
(
url
);
console
.
log
(
url
);
wssh
.
sock
=
sock
;
wssh
.
term
=
term
;
term
.
on
(
'data'
,
function
(
data
)
{
term
.
on
(
'data'
,
function
(
data
)
{
// console.log(data);
// console.log(data);
sock
et
.
send
(
JSON
.
stringify
({
'data'
:
data
}));
sock
.
send
(
JSON
.
stringify
({
'data'
:
data
}));
});
});
sock
et
.
onopen
=
function
(
e
)
{
sock
.
onopen
=
function
(
)
{
$
(
'.container'
).
hide
();
$
(
'.container'
).
hide
();
term
.
open
(
terminal
,
true
);
term
.
open
(
terminal
,
true
);
term
.
toggleFullscreen
(
true
);
term
.
toggleFullscreen
(
true
);
};
};
socket
.
onmessage
=
function
(
msg
)
{
sock
.
onmessage
=
function
(
msg
)
{
var
reader
=
new
FileReader
();
var
reader
=
new
window
.
FileReader
();
reader
.
onloadend
=
function
(
event
){
var
decoder
=
new
TextDecoder
();
reader
.
onloadend
=
function
(){
var
decoder
=
new
window
.
TextDecoder
();
var
text
=
decoder
.
decode
(
reader
.
result
);
var
text
=
decoder
.
decode
(
reader
.
result
);
// console.log(text);
// console.log(text);
term
.
write
(
text
);
term
.
write
(
text
);
if
(
!
term
.
resized
)
{
if
(
!
term
.
resized
)
{
resize_term
(
term
,
sock
et
);
resize_term
(
term
,
sock
);
term
.
resized
=
true
;
term
.
resized
=
true
;
}
}
};
};
reader
.
readAsArrayBuffer
(
msg
.
data
);
reader
.
readAsArrayBuffer
(
msg
.
data
);
};
};
sock
et
.
onerror
=
function
(
e
)
{
sock
.
onerror
=
function
(
e
)
{
console
.
log
(
e
);
console
.
log
(
e
);
};
};
sock
et
.
onclose
=
function
(
e
)
{
sock
.
onclose
=
function
(
e
)
{
console
.
log
(
e
);
console
.
log
(
e
);
term
.
destroy
();
term
.
destroy
();
term
=
undefined
;
wssh
.
term
=
undefined
;
socket
=
undefined
;
wssh
.
sock
=
undefined
;
$
(
'.container'
).
show
();
$
(
'.container'
).
show
();
status
.
text
(
e
.
reason
);
status
.
text
(
e
.
reason
);
btn
.
prop
(
'disabled'
,
false
);
btn
.
prop
(
'disabled'
,
false
);
...
@@ -134,9 +112,44 @@ jQuery(function($){
...
@@ -134,9 +112,44 @@ jQuery(function($){
}
}
$
(
'form#connect'
).
submit
(
function
(
event
)
{
event
.
preventDefault
();
var
form
=
$
(
this
),
url
=
form
.
attr
(
'action'
),
type
=
form
.
attr
(
'type'
),
data
=
new
FormData
(
this
);
if
(
!
data
.
get
(
'hostname'
)
||
!
data
.
get
(
'port'
)
||
!
data
.
get
(
'username'
))
{
status
.
text
(
'Hostname, port and username are required.'
);
return
;
}
var
pk
=
data
.
get
(
'privatekey'
);
if
(
pk
&&
pk
.
size
>
16384
)
{
status
.
text
(
'Key size exceeds maximum value.'
);
return
;
}
status
.
text
(
''
);
btn
.
prop
(
'disabled'
,
true
);
$
.
ajax
({
url
:
url
,
type
:
type
,
data
:
data
,
success
:
callback
,
cache
:
false
,
contentType
:
false
,
processData
:
false
});
});
$
(
window
).
resize
(
function
(){
$
(
window
).
resize
(
function
(){
if
(
typeof
term
!=
'undefined'
&&
typeof
socket
!=
'undefined'
)
{
if
(
wssh
.
term
&&
wssh
.
sock
)
{
resize_term
(
term
,
socket
);
resize_term
(
wssh
.
term
,
wssh
.
sock
);
}
}
});
});
...
...
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