Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
N
noVNC
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
rasky
noVNC
Commits
5d2c3864
Commit
5d2c3864
authored
Apr 16, 2010
by
Joel Martin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reassemble partial client packets in wsproxy.py
parent
af7a3193
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
18 deletions
+51
-18
vnc.js
vnc.js
+20
-14
wsproxy.py
wsproxy.py
+31
-4
No files found.
vnc.js
View file @
5d2c3864
...
...
@@ -802,33 +802,39 @@ init_ws: function () {
console
.
log
(
"connecting to "
+
uri
);
RFB
.
ws
=
new
WebSocket
(
uri
);
RFB
.
ws
.
onmessage
=
function
(
e
)
{
//console.log(">> onmessage");
//console.log(">>
WebSockets.
onmessage");
RFB
.
d
=
RFB
.
d
.
concat
(
Base64
.
decode
(
e
.
data
));
if
(
RFB
.
state
!=
'normal'
)
{
RFB
.
init_msg
();
}
else
{
RFB
.
normal_msg
();
}
if
(
RFB
.
state
==
'reset'
)
{
if
(
RFB
.
state
==
'closed'
)
{
console
.
log
(
"onmessage while close"
);
}
else
if
(
RFB
.
state
==
'reset'
)
{
/* close and reset connection */
RFB
.
disconnect
();
RFB
.
init_ws
();
}
else
if
(
RFB
.
state
==
'failed'
)
{
console
.
log
(
"Giving up!"
);
RFB
.
disconnect
();
}
else
if
(
RFB
.
state
!=
'normal'
)
{
RFB
.
init_msg
();
}
else
{
RFB
.
normal_msg
();
}
//console.log("<< onmessage");
//console.log("<<
WebSockets.
onmessage");
};
RFB
.
ws
.
onopen
=
function
(
e
)
{
console
.
log
(
">> onopen"
);
console
.
log
(
">>
WebSockets.
onopen"
);
RFB
.
state
=
"ProtocolVersion"
;
console
.
log
(
"<< onopen"
);
console
.
log
(
"<<
WebSockets.
onopen"
);
};
RFB
.
ws
.
onclose
=
function
(
e
)
{
console
.
log
(
">> onclose"
);
console
.
log
(
">>
WebSockets.
onclose"
);
RFB
.
state
=
"closed"
;
console
.
log
(
"<< onclose"
);
}
console
.
log
(
"<< WebSockets.onclose"
);
};
RFB
.
ws
.
onerror
=
function
(
e
)
{
console
.
log
(
">> WebSockets.onerror"
);
console
.
log
(
" "
+
e
);
console
.
log
(
"<< WebSockets.onerror"
);
};
console
.
log
(
"<< init_ws"
);
},
...
...
@@ -838,7 +844,7 @@ connect: function () {
RFB
.
host
=
$
(
'host'
).
value
;
RFB
.
port
=
$
(
'port'
).
value
;
RFB
.
password
=
$
(
'password'
).
value
;
if
((
!
host
)
||
(
!
port
))
{
if
((
!
RFB
.
host
)
||
(
!
RFB
.
port
))
{
console
.
log
(
"must set host and port"
);
return
;
}
...
...
wsproxy.py
View file @
5d2c3864
...
...
@@ -15,8 +15,16 @@ WebSocket-Protocol: sample\r
\r
"""
policy_response
=
"""<cross-domain-policy><allow-access-from domain="*" to-ports="*" /></cross-domain-policy>"""
def
handshake
(
client
):
handshake
=
client
.
recv
(
255
)
handshake
=
client
.
recv
(
1024
)
print
"Handshake [
%
s]"
%
handshake
if
handshake
.
startswith
(
"<policy-file-request/>"
):
print
"Sending:"
,
policy_response
client
.
send
(
policy_response
)
handshake
=
client
.
recv
(
1024
)
print
"Handshake [
%
s]"
%
handshake
req_lines
=
handshake
.
split
(
"
\r\n
"
)
_
,
path
,
_
=
req_lines
[
0
]
.
split
(
" "
)
_
,
origin
=
req_lines
[
4
]
.
split
(
" "
)
...
...
@@ -27,8 +35,17 @@ def traffic(token="."):
sys
.
stdout
.
write
(
token
)
sys
.
stdout
.
flush
()
def
decode
(
buf
):
""" Parse out WebSocket packets. """
if
buf
.
count
(
'
\xff
'
)
>
1
:
return
[
d
[
1
:]
for
d
in
buf
.
split
(
'
\xff
'
)]
else
:
return
[
b64decode
(
buf
[
1
:
-
1
])]
def
proxy
(
client
,
target
):
""" Proxy WebSocket to normal socket. """
cqueue
=
[]
cpartial
=
""
tqueue
=
[]
socks
=
[
client
,
target
]
...
...
@@ -39,9 +56,19 @@ def proxy(client, target):
if
client
in
ins
:
buf
=
client
.
recv
(
buffer_size
)
if
len
(
buf
)
==
0
:
raise
Exception
(
"Client closed"
)
tqueue
.
append
(
b64decode
(
buf
[
1
:
-
1
]))
#print "Client recv: %s (%d)" % (repr(buf[1:-1]), len(buf))
if
buf
[
-
1
]
==
"
\xff
"
:
if
cpartial
:
tqueue
.
extend
(
decode
(
cpartial
+
buf
))
cpartial
=
""
else
:
tqueue
.
extend
(
decode
(
buf
))
traffic
(
"}"
)
else
:
traffic
(
".}"
)
cpartial
=
cpartial
+
buf
#print "Client recv: %s (%d)" % (repr(buf, len(buf))
if
target
in
ins
:
buf
=
target
.
recv
(
buffer_size
)
...
...
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