Commit Graph

66 Commits

Author SHA1 Message Date
Joel Martin 932e7318b9 Minor correct to wstelnet.js header comment. 2011-01-12 16:55:31 -06:00
Joel Martin f2538f337d wsproxy, wstelnet: wrap command, WS telnet client.
wswrapper:

    Getting the wswrapper.c LD_PRELOAD model working has turned out to
    involve too many dark corners of the glibc/POSIX file descriptor
    space. I realized that 95% of what I want can be accomplished by
    adding a "wrap command" mode to wsproxy.

    The code is still there for now, but consider it experimental at
    best. Minor fix to dup2 and add dup and dup3 logging.

wsproxy Wrap Command:

    In wsproxy wrap command mode, a command line is specified instead
    of a target address and port. wsproxy then uses a much simpler
    LD_PRELOAD library, rebind.so, to move intercept any bind() system
    calls made by the program. If the bind() call is for the wsproxy
    listen port number then the real bind() system call is issued for
    an alternate (free high) port on loopback/localhost.  wsproxy then
    forwards from the listen address/port to the moved port.

    The --wrap-mode argument takes three options that determine the
    behavior of wsproxy when the wrapped command returns an exit code
    (exit or daemonizing): ignore, exit, respawn.

    For example, this runs vncserver on turns port 5901 into
    a WebSockets port (rebind.so must be built first):

        ./utils/wsproxy.py --wrap-mode=ignore 5901 -- vncserver :1

    The vncserver command backgrounds itself so the wrap mode is set
    to "ignore" so that wsproxy keeps running even after it receives
    an exit code from vncserver.

wstelnet:

    To demonstrate the wrap command mode, I added WebSockets telnet
    client.

    For example, this runs telnetd (krb5-telnetd) on turns port 2023
    into a WebSockets port (using "respawn" mode since telnetd exits
    after each connection closes):

        sudo ./utils/wsproxy.py --wrap-mode=respawn 2023 -- telnetd -debug 2023

    Then the utils/wstelnet.html page can be used to connect to the
    telnetd server on port 2023. The telnet client includes VT100.js
    (from http://code.google.com/p/sshconsole) which handles the
    terminal emulation and rendering.

rebind:

    The rebind LD_PRELOAD library is used by wsproxy in wrap command
    mode to intercept bind() system calls and move the port to
    a different port on loopback/localhost. The rebind.so library can
    be built by running make in the utils directory.

    The rebind library can be used separately from wsproxy by setting
    the REBIND_OLD_PORT and REBIND_NEW_PORT environment variables
    prior to executing a command. For example:

        export export REBIND_PORT_OLD="23"
        export export REBIND_PORT_NEW="65023"
        LD_PRELOAD=./rebind.so telnetd -debug 23

    Alternately, the rebind script does the same thing:

        rebind 23 65023 telnetd -debug 23

Other changes/notes:

- wsproxy no longer daemonizes by default. Remove -f/--foreground
  option and add -D/--deamon option.

- When wsproxy is used to wrap a command in "respawn" mode, the
  command will not be respawn more often than 3 times within 10
  seconds.

- Move getKeysym routine out of Canvas object so that it can be called
  directly.
2011-01-12 13:15:11 -06:00
Joel Martin 86725f9b4c wswrapper: add dup2, fix select w/ NULL timeout.
- add dup2 functionality. This requires adding a ref cnt to the
  _WS_connections structure so that we only free the structure once
  all dup'd referenced are closed. Also, refactor malloc and free of
  connection structure into _WS_alloc and _WS_free.
- allow select to accept a NULL timeout value which means sleep
  forever instead of segfaulting.
- fix some compile warnings related to ppoll definition.
- move some WebSockets related html test pages into utils and symlink
  them from tests.
2011-01-08 21:46:36 -06:00
Joel Martin 6a88340929 Refactor and cleanup websocket.py and deps.
Moved websocket.py code into a class WebSocketServer. WebSockets
server implementations will sub-class and define a handler() method
which is passed the client socket after. Global variable settings have been
changed to be parameters for WebSocketServer when created.

Subclass implementations still have to handle queueing and sending but
the parent class handles everything else (daemonizing, websocket
handshake, encode/decode, etc). It would be better if the parent class
could handle queueing and sending. This adds some buffering and
polling complexity to the parent class but it would be better to do so
at some point. However, the result is still much cleaner as can be
seen in wsecho.py.

Refactored wsproxy.py and wstest.py (formerly ws.py) to use the new
class. Added wsecho.py as a simple echo server.

- rename tests/ws.py to utils/wstest.py and add a symlink from
  tests/wstest.py

- rename tests/ws.html to tests/wstest.html to match utils/wstest.py.

- add utils/wsecho.py

- add tests/wsecho.html which communicates with wsecho.py and simply
  sends periodic messages and shows what is received.
2011-01-08 15:29:01 -06:00
Joel Martin 6ace64d3ae utils/README.md: horizontal looks better.
Flip table back to be horizontal. More readable.
2011-01-06 19:21:17 -06:00
Joel Martin 90966d6251 utils/README.md: flip table. Add web server info.
Flip the feature table to be tall instead of wide.

Added row about "web server" functionality in wsproxy.py.
2011-01-06 19:17:32 -06:00
Joel Martin 9aaf26e878 Merge branch 'master' of git@github.com:kanaka/noVNC 2011-01-06 19:13:39 -06:00
Joel Martin 02a7dd2c29 Merge branch 'master' of git@github.com:kanaka/noVNC 2011-01-06 17:33:22 -07:00
Joel Martin 96bc3d3088 wsproxy.py: add web serving capability.
- Added ability to respond to normal web requests. This is basically
  integrating web.py functionality into wsproxy. This is only in the
  python version and it is off by default when calling wsproxy. Turn
  it on with --web DIR where DIR is the web root directory.

Next task is to clean up wsproxy.py. It's gotten unwieldy and it
really no longer needs to be parallel to the C version.
2011-01-06 18:26:54 -06:00
Joel Martin 58dc1947de wsproxy: warn when no cert. C sock close cleanup.
Warn early about no SSL cert and add clearer warning when a connection
comes in as SSL but no cert file exists.

For the C version, cleanup closing of the connection socket. Use
shutdown for a cleaner cleanup with the client.
2011-01-04 13:14:46 -06:00
Joel Martin 2574936f60 utils/README.md, docs/TODO, docs/notes: updates.
Add wswrapper info to utils/README.md and docs/TODO. Remove innacurate
info from docs/notes.
2010-12-30 11:00:50 -07:00
Joel Martin 71ba9a7a54 wswrapper: update README, DO_MSG def for output.
Update README to mention wswrapper. Add DO_MSG define which controls
whether wswrapper code generates basic output.
2010-12-29 14:11:28 -07:00
Joel Martin 56d9aa816b wswrapper: interpose on poll/ppoll also.
poll/ppoll interposer builds but is untested.
2010-12-27 19:44:14 -07:00
Joel Martin 64dbc6bb63 wswrapper: timeout select.
The select call needs to timeout if a WebSocket socket keeps reporting
ready but actually isn't ready. To prevent it hanging forever in that
condition, the timeout value is now adjusted now for each call.

Move the DO_DEBUG and DO_TRACE settings to wswrapper.c.
2010-12-27 16:08:27 -07:00
Joel Martin 6b900d25d0 wswrapper: interpose select/pselect. Cleaup.
Interpose on select/pselect so that WebSockets sockets are only
reported as ready if they have enough to actually decode at least
1 byte of real data. This prevents hanging in read/recv after
WebSocket is reported as ready but is not actually ready because empty
frames or less than four base64 bytes have been received.

Split defines and constant defintions into wswrapper.h.

Cleanup debug output and add TRACE for more detailed tracing debug
output.

Major TODO is that select needs to timeout if WebSocket socket keeps
reporting ready but actually isn't ready. That condition will
currently hang forever because the select timeout value is not
adjusted when looping.
2010-12-27 13:21:07 -07:00
Joel Martin 0f7f146f20 utils/launch.sh: find top web dir (with vnc.html). 2010-12-21 10:17:43 -06:00
Amir Malik b992f7c7dd use cd, dirname, and pwd to determine path instead of readlink (Mac fix) 2010-12-22 00:15:33 +08:00
Amir Malik a22a3cc0ea set socket option SO_REUSEADDR to prevent "Address already in use" error 2010-12-21 23:31:46 +08:00
Joel Martin 40a653f555 wswrapper: fix preload path and interpose port.
Make path to ld preload library absolute so wswrapper works even if
path is changed before main program is executed (i.e. by the vncserver
wrapper script).

bind() was using the return value for the port number, but it's
actually the original port number that we should interpose on in the
bind() routine.
2010-12-16 14:04:16 -06:00
Joel Martin b144a0933d wswrapper: Normalize comments, remove unused headers. 2010-12-14 13:14:21 -05:00
Joel Martin c99124b527 wswrapper: Allow multiple WebSockets connections.
Allocate buffer and state memory for each accepted connection. This
allows all WebSockets connections to a given listen port to be wrapped
with WebSockets support.
2010-12-14 13:14:12 -05:00
Joel Martin 70c585968b wswrap: WSWRAP_PORT envvar and wswrap script.
wswrapper.so will only interpose on the listen port specified in
WSWRAP_PORT.

Add simple wswrap script that sets the WSWRAP_PORT, LD_PRELOAD and
invokes the command line to wrap.
2010-12-13 14:20:34 -05:00
Joel Martin 5b0bbd5c12 wswrapper: wrap existing server using LD_PRELOAD.
wswrapper.so is LD_PRELOAD shared library that interposes and turns
a generic TCP socket into a WebSockets service.

This current version works but will only allow work for a single
connection, subsequent connections will not be wrapped. In addition
the wrapper interposes on the first incoming network connection. It
should read an environment variable to determine the port to interpose
on. Also, should limit origin based on another environment variable.
Then there should be a wswrap setup script that allows easier
invocation.
2010-12-02 22:11:02 -06:00
Joel Martin e66f3f89f2 Add Chrome Frame support. Close requests in web.py.
- Add meta tag to vnc.html and vnc_auto.html so that if Chrome Frame
  is installed, it is used.

- Add detection to default_controls.js that shows a message with
  a Chrome Frame install link if the user is using a version of IE
  without Canvas support.

- Fix web.py so that requests have their connection closed after they
  are completed.  This has been a bug for a while but it prevents
  Chrome Frame from working because Chrome Frame doesn't activate
  until the initial request connection closes.
2010-11-09 12:06:03 -06:00
Joel Martin 1ee2d93e94 wsproxy.js: Fix multi-frame decoding.
- Also, discovered node.js bug in base64 decoding. Added test case and
  filed https://github.com/ry/node/issues/issue/402
2010-11-07 22:28:08 -06:00
Joel Martin fd758dd335 First pass at wsproxy using node (node.js).
Node:
    http://nodejs.org/
    https://github.com/ry/node

It mostly works, but it eventually gets an error from the target which
is probably due to missing support for re-assembly of client
WebSockets frames.
2010-11-07 19:06:20 -06:00
Joel Martin 58b4c9408f wsproxy: Fix --key parameter use. 2010-11-06 14:12:37 -05:00
Joel Martin 3205a3dee8 Add --key option for separate cert and key file.
If only --cert is specified then continue to assume both certificate
and key are in the same file (key first).
2010-11-06 10:55:09 -05:00
Joel Martin e70f1d947e Remove left over record code. Squelch compile warnings 2010-11-06 10:53:32 -05:00
François Revol f61274c827 wsproxy: Mac OS X build fixes
- pass CFLAGS and LDFLAGS in case one needs to use -m32
- link to libcrypto for _ERR_print_errors_fp
- __THROW is non-standard define it to nothing by default
- use b64_ntop and b64_pton instead of mangled versions, OSX doesn't mangle them in the same way
- access() takes two arguments!

Signed-off-by: François Revol <revol@free.fr>
2010-11-06 10:04:24 -05:00
Joel Martin 3dc3135b21 utils/README.md: second try on cmd formatting. 2010-10-28 10:53:08 -05:00
Joel Martin 6502293f21 utils/README.md: Fix command formatting. 2010-10-28 10:52:27 -05:00
Joel Martin e5d60a8ba2 Issue #32, wsproxy README, update webkit bug info,
- Add wsproxy README.md in utils/ directory.

- Document how to build ssl module for python 2.5 and older in wsproxy
  README.

- Update browsers.md to note revision that have the webkit Canvas
  rendering bug: WebKit build 66396 through 68867 (Chrome/Chromium
  build 57968 through 61278).
2010-10-28 10:45:26 -05:00
Joel Martin c084c396ba utils/Makefile: clean up md5.o too. 2010-10-04 13:30:53 -04:00
Joel Martin a679a97d1b Show rect/enc counts, add vnc_perf.html test.
- include/rfb.js: Keep track of the number of rects of each encoding
  type and print them out when we close a connection (if 'info'
  logging level).

- tests/vnc_perf.html: first pass at a noVNC based performance
  benchmark.

- utils/wsproxy.py: Fix the output of the record filename.
2010-09-25 15:50:43 -05:00
Joel Martin 005d9ee999 Misc cleanup: debug logging, record filename, etc.
- include/canvas.js: When 'debug' logging, show browser detection
  values.
- test/canvas.html: Only restore the canvas to it's starting state if
  the logging level is not 'debug'.
- wsproxy.py: Append the session number to the record filename so that
  multiple sessions don't stomp on each other.
2010-09-23 08:17:00 -05:00
Joel Martin 02889945cb C proxy: Issue #14: wss:// from Safari
Addresses this issue:
http://github.com/kanaka/noVNC/issues#issue/14

This goes along with commit 7e63919e6 but for the C proxy.
2010-09-15 18:21:42 -05:00
Joel Martin 7e63919e6d proxy: Issue #14: detect and allow wss:// from Safari.
Addresses this issue:
http://github.com/kanaka/noVNC/issues#issue/14

Safari starts with '\x80' rather than '\x16' like Chrome and Firefox
and having PROTOCOL_TLSv1 doesn't work with Safari. But just removing
the ssl_version allows things to work with Safari wss:// connections.

Also, if the handshake (after SSL wrapping) is null then terminate the
connection. This probably means the certificate was refused by the
client. Unfortunately Safari (the version I have) doesn't cleanly
shutdown WebSockets connections until the page is reloaded (even if
the object is no longer referenced).
2010-09-15 12:19:17 -05:00
Joel Martin cc374cd61a proxy: always multiprocess and add --verbose.
Always fork handlers processes. Instead printing traffic when
single-processing, print traffic if verbose flag given.
2010-09-11 15:10:54 -05:00
Joel Martin edc4725260 proxy: do handshake in forked process too. 2010-09-10 14:31:34 -05:00
Joel Martin a0315ab1dc wsproxy: multiprocess capable.
Add -m, --multiprocess option which forks a handler for each
connection allowing multiple connections to the same target using the
same proxy instance.

Cleaned up the output of the handler process. Each process' output is
prefixed with an ordinal value.

Changed both the C and python versions of the proxy.
2010-09-10 13:05:48 -05:00
Joel Martin 465faf19db Remove record option from C wsproxy.
I've decided that debug/develop/extra features will just be in the
python version of the proxy. The C version (and other versions) will
just have the core functionality (unless someone wants to support it).
2010-09-10 09:58:26 -05:00
Joel Martin 55dee43279 Remove psuedo-UTF8 encoding.
It's less efficient on average that base64 (150% vs 133%). It's
non-standard (0 shifted to 256 before encoding). And I rarely use it.
2010-08-27 12:10:09 -05:00
Joel Martin fb007628d6 Add Javascript variable container to record data.
- This allows the recorded data to be immediately usable by
  tests/vnc_playback.html
2010-08-12 09:50:49 -05:00
Joel Martin 4ed717ad31 Scroll render test and perf speedup.
Turns out when Windows is running in QEMU and a window scroll happens,
there are lots of little hextile rects sent. This is slow in noVNC.

- Some recording/playback improvement.
- Add test harness to drive playback of recordings.
- By pulling off the rect header in one chunk we get a 3X speedup in
  Chrome and a 20% speedup in firefox (specifically for the scroll
  test).
- Also, get rid of some noise from creating timers for handle_message.
  Check to make sure there isn't already a pending timer first.
2010-08-06 16:43:24 -05:00
Joel Martin a6a1ad3d0a Remove unused imports (sys, ssl) in wsproxy.py 2010-08-04 14:33:32 -05:00
Joel Martin 5958fb4996 Python 2.4 compatible imports.
- Fallback to md5 module if hashlib not there.
- Import parse_qsl from cgi where it is in both 2.4 and 2.6
2010-08-04 14:32:10 -05:00
Joel Martin c95c24e743 Fix #19: python2.4 support.
- Replace URL parsing using "".partition() with urlparse module.
2010-08-04 14:18:55 -05:00
Joel Martin 801482be6a WebSockets orderly/clean close frame.
- When a packet with only '\xff\x00' is received, this means the
  client is doing an orderly shutdown. (WebSockets spec version 76)
2010-08-03 13:23:59 -05:00
Joel Martin 1656b1b98d Fix listen_port check.
Interestingly, the bug depends on compiler behavior. If local
variables are automatically initialized to 0, then this always caused
the program to error out indicating a failure to parse the listen
port. Otherwise, the test was a no-op (except the rare case where the
memory happened to be zero anyways).

Thanks to Eugen Melnikoff for finding this.
2010-07-17 12:13:54 -05:00