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
0e7a8c1a
Commit
0e7a8c1a
authored
Mar 03, 2016
by
liuzheng712
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(webterminal): test
parent
b1f0297e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
94 additions
and
85 deletions
+94
-85
webterminal.js
static/js/webterminal.js
+94
-85
No files found.
static/js/webterminal.js
View file @
0e7a8c1a
...
...
@@ -2,100 +2,109 @@
* Created by liuzheng on 3/3/16.
*/
var
rowHeight
=
1
;
var
colWidth
=
1
;
function
WSSHClient
()
{
}
var
colWidth
=
1
;
function
WSSHClient
()
{
}
WSSHClient
.
prototype
.
_generateEndpoint
=
function
(
options
)
{
console
.
log
(
options
);
if
(
window
.
location
.
protocol
==
'https:'
)
{
var
protocol
=
'wss://'
;
}
else
{
var
protocol
=
'ws://'
;
}
WSSHClient
.
prototype
.
connect
=
function
(
options
)
{
var
endpoint
=
'{{ web_terminal_url }}'
;
var
endpoint
=
protocol
+
window
.
location
.
host
+
':8080'
+
'/terminal'
;
return
endpoint
;
};
WSSHClient
.
prototype
.
connect
=
function
(
options
)
{
var
endpoint
=
this
.
_generateEndpoint
(
options
);
if
(
window
.
WebSocket
)
{
this
.
_connection
=
new
WebSocket
(
endpoint
);
}
else
if
(
window
.
MozWebSocket
)
{
this
.
_connection
=
MozWebSocket
(
endpoint
);
}
else
{
options
.
onError
(
'WebSocket Not Supported'
);
return
;
}
if
(
window
.
WebSocket
)
{
this
.
_connection
=
new
WebSocket
(
endpoint
);
}
else
if
(
window
.
MozWebSocket
)
{
this
.
_connection
=
MozWebSocket
(
endpoint
);
}
else
{
options
.
onError
(
'WebSocket Not Supported'
);
return
;
}
this
.
_connection
.
onopen
=
function
()
{
options
.
onConnect
();
};
this
.
_connection
.
onopen
=
function
()
{
options
.
onConnect
();
};
this
.
_connection
.
onmessage
=
function
(
evt
)
{
var
data
=
JSON
.
parse
(
evt
.
data
.
toString
());
if
(
data
.
error
!==
undefined
)
{
options
.
onError
(
data
.
error
);
}
else
{
options
.
onData
(
data
.
data
);
}
};
this
.
_connection
.
onmessage
=
function
(
evt
)
{
var
data
=
JSON
.
parse
(
evt
.
data
.
toString
());
if
(
data
.
error
!==
undefined
)
{
options
.
onError
(
data
.
error
);
}
else
{
options
.
onData
(
data
.
data
);
}
};
this
.
_connection
.
onclose
=
function
(
evt
)
{
options
.
onClose
();
};
};
this
.
_connection
.
onclose
=
function
(
evt
)
{
options
.
onClose
();
};
};
WSSHClient
.
prototype
.
send
=
function
(
data
)
{
this
.
_connection
.
send
(
JSON
.
stringify
({
'data'
:
data
}));
};
WSSHClient
.
prototype
.
send
=
function
(
data
)
{
this
.
_connection
.
send
(
JSON
.
stringify
({
'data'
:
data
}));
};
function
openTerminal
(
options
)
{
var
client
=
new
WSSHClient
();
var
term
=
new
Terminal
(
80
,
24
,
function
(
key
)
{
client
.
send
(
key
);
});
term
.
open
();
$
(
'.terminal'
).
detach
().
appendTo
(
'#term'
);
term
.
resize
(
80
,
24
);
term
.
write
(
'Connecting...'
);
client
.
connect
(
$
.
extend
(
options
,
{
onError
:
function
(
error
)
{
term
.
write
(
'Error: '
+
error
+
'
\
r
\
n'
);
},
onConnect
:
function
()
{
// Erase our connecting message
term
.
write
(
'
\
r'
);
},
onClose
:
function
()
{
term
.
write
(
'Connection Reset By Peer'
);
},
onData
:
function
(
data
)
{
term
.
write
(
data
);
}
}));
rowHeight
=
0.0
+
1.00
*
$
(
'.terminal'
).
height
()
/
24
;
colWidth
=
0.0
+
1.00
*
$
(
'.terminal'
).
width
()
/
80
;
return
{
'term'
:
term
,
'client'
:
client
};
}
function
openTerminal
(
options
)
{
var
client
=
new
WSSHClient
();
var
term
=
new
Terminal
(
80
,
24
,
function
(
key
)
{
client
.
send
(
key
);
});
term
.
open
();
$
(
'.terminal'
).
detach
().
appendTo
(
'#term'
);
term
.
resize
(
80
,
24
);
term
.
write
(
'Connecting...'
);
client
.
connect
(
$
.
extend
(
options
,
{
onError
:
function
(
error
)
{
term
.
write
(
'Error: '
+
error
+
'
\
r
\
n'
);
},
onConnect
:
function
()
{
// Erase our connecting message
term
.
write
(
'
\
r'
);
},
onClose
:
function
()
{
term
.
write
(
'Connection Reset By Peer'
);
},
onData
:
function
(
data
)
{
term
.
write
(
data
);
}
}));
rowHeight
=
0.0
+
1.00
*
$
(
'.terminal'
).
height
()
/
24
;
colWidth
=
0.0
+
1.00
*
$
(
'.terminal'
).
width
()
/
80
;
return
{
'term'
:
term
,
'client'
:
client
};
}
function
resize
()
{
$
(
'.terminal'
).
css
(
'width'
,
window
.
innerWidth
-
25
);
console
.
log
(
window
.
innerWidth
);
console
.
log
(
window
.
innerWidth
-
10
);
var
rows
=
Math
.
floor
(
window
.
innerHeight
/
rowHeight
)
-
2
;
var
cols
=
Math
.
floor
(
window
.
innerWidth
/
colWidth
)
-
1
;
function
resize
()
{
$
(
'.terminal'
).
css
(
'width'
,
window
.
innerWidth
-
25
);
console
.
log
(
window
.
innerWidth
);
console
.
log
(
window
.
innerWidth
-
10
);
var
rows
=
Math
.
floor
(
window
.
innerHeight
/
rowHeight
)
-
2
;
var
cols
=
Math
.
floor
(
window
.
innerWidth
/
colWidth
)
-
1
;
return
{
rows
:
rows
,
cols
:
cols
};
}
return
{
rows
:
rows
,
cols
:
cols
};
}
$
(
document
).
ready
(
function
()
{
var
options
=
{
};
$
(
document
).
ready
(
function
()
{
var
options
=
{};
$
(
'#ssh'
).
show
();
var
term_client
=
openTerminal
(
options
);
console
.
log
(
rowHeight
);
$
(
'#ssh'
).
show
();
var
term_client
=
openTerminal
(
options
);
console
.
log
(
rowHeight
);
window
.
onresize
=
function
()
{
var
geom
=
resize
();
console
.
log
(
geom
);
term_client
.
term
.
resize
(
geom
.
cols
,
geom
.
rows
);
term_client
.
client
.
send
({
'resize'
:
{
'rows'
:
geom
.
rows
,
'cols'
:
geom
.
cols
}});
$
(
'#ssh'
).
show
();
}
window
.
onresize
=
function
()
{
var
geom
=
resize
();
console
.
log
(
geom
);
term_client
.
term
.
resize
(
geom
.
cols
,
geom
.
rows
);
term_client
.
client
.
send
({
'resize'
:
{
'rows'
:
geom
.
rows
,
'cols'
:
geom
.
cols
}});
$
(
'#ssh'
).
show
();
}
});
\ No newline at end of file
});
\ No newline at end of file
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