~0x44/nova/bug838466

« back to all changes in this revision

Viewing changes to bin/nova-vncproxy

  • Committer: Brian Waldon
  • Date: 2011-07-29 16:54:55 UTC
  • mto: This revision was merged to the branch mainline in revision 1364.
  • Revision ID: brian.waldon@rackspace.com-20110729165455-4ebqwv8s5pkscmmg
one last change

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 
3
 
 
4
# Copyright (c) 2010 Openstack, LLC.
 
5
# All Rights Reserved.
 
6
#
 
7
#    Licensed under the Apache License, Version 2.0 (the "License");
 
8
#    you may not use this file except in compliance with the License.
 
9
#    You may obtain a copy of the License at
 
10
#
 
11
#        http://www.apache.org/licenses/LICENSE-2.0
 
12
#
 
13
#    Unless required by applicable law or agreed to in writing, software
 
14
#    distributed under the License is distributed on an "AS IS" BASIS,
 
15
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
16
#    See the License for the specific language governing permissions and
 
17
#    limitations under the License.
 
18
 
 
19
"""VNC Console Proxy Server."""
 
20
 
 
21
import eventlet
 
22
import gettext
 
23
import os
 
24
import sys
 
25
 
 
26
possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
 
27
                                   os.pardir,
 
28
                                   os.pardir))
 
29
if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')):
 
30
    sys.path.insert(0, possible_topdir)
 
31
 
 
32
gettext.install('nova', unicode=1)
 
33
 
 
34
from nova import flags
 
35
from nova import log as logging
 
36
from nova import service
 
37
from nova import utils
 
38
from nova import wsgi
 
39
from nova import version
 
40
from nova.vnc import auth
 
41
from nova.vnc import proxy
 
42
 
 
43
 
 
44
LOG = logging.getLogger('nova.vnc-proxy')
 
45
 
 
46
 
 
47
FLAGS = flags.FLAGS
 
48
flags.DEFINE_string('vncproxy_wwwroot', '/var/lib/nova/noVNC/',
 
49
                     'Full path to noVNC directory')
 
50
flags.DEFINE_boolean('vnc_debug', False,
 
51
                     'Enable debugging features, like token bypassing')
 
52
flags.DEFINE_integer('vncproxy_port', 6080,
 
53
                     'Port that the VNC proxy should bind to')
 
54
flags.DEFINE_string('vncproxy_host', '0.0.0.0',
 
55
                     'Address that the VNC proxy should bind to')
 
56
flags.DEFINE_integer('vnc_token_ttl', 300,
 
57
                     'How many seconds before deleting tokens')
 
58
flags.DEFINE_string('vncproxy_manager', 'nova.vnc.auth.VNCProxyAuthManager',
 
59
                    'Manager for vncproxy auth')
 
60
 
 
61
flags.DEFINE_flag(flags.HelpFlag())
 
62
flags.DEFINE_flag(flags.HelpshortFlag())
 
63
flags.DEFINE_flag(flags.HelpXMLFlag())
 
64
 
 
65
 
 
66
def handle_flash_socket_policy(socket):
 
67
    LOG.info(_("Received connection on flash socket policy port"))
 
68
 
 
69
    fd = socket.makefile('rw')
 
70
    expected_command = "<policy-file-request/>"
 
71
    if expected_command in fd.read(len(expected_command) + 1):
 
72
        LOG.info(_("Received valid flash socket policy request"))
 
73
        fd.write('<?xml version="1.0"?><cross-domain-policy><allow-'
 
74
                 'access-from domain="*" to-ports="%d" /></cross-'
 
75
                 'domain-policy>' % (FLAGS.vncproxy_port))
 
76
        fd.flush()
 
77
    socket.close()
 
78
 
 
79
if __name__ == "__main__":
 
80
    utils.default_flagfile()
 
81
    FLAGS(sys.argv)
 
82
    logging.setup()
 
83
 
 
84
    LOG.audit(_("Starting nova-vnc-proxy node (version %s)"),
 
85
              version.version_string_with_vcs())
 
86
 
 
87
    if not (os.path.exists(FLAGS.vncproxy_wwwroot) and
 
88
            os.path.exists(FLAGS.vncproxy_wwwroot + '/vnc_auto.html')):
 
89
        LOG.info(_("Missing vncproxy_wwwroot (version %s)"),
 
90
                    FLAGS.vncproxy_wwwroot)
 
91
        LOG.info(_("You need a slightly modified version of noVNC "
 
92
                   "to work with the nova-vnc-proxy"))
 
93
        LOG.info(_("Check out the most recent nova noVNC code: %s"),
 
94
                   "git://github.com/sleepsonthefloor/noVNC.git")
 
95
        LOG.info(_("And drop it in %s"), FLAGS.vncproxy_wwwroot)
 
96
        exit(1)
 
97
 
 
98
    app = proxy.WebsocketVNCProxy(FLAGS.vncproxy_wwwroot)
 
99
 
 
100
    LOG.audit(_("Allowing access to the following files: %s"),
 
101
              app.get_whitelist())
 
102
 
 
103
    with_logging = auth.LoggingMiddleware(app)
 
104
 
 
105
    if FLAGS.vnc_debug:
 
106
        with_auth = proxy.DebugMiddleware(with_logging)
 
107
    else:
 
108
        with_auth = auth.VNCNovaAuthMiddleware(with_logging)
 
109
 
 
110
    service.serve()
 
111
 
 
112
    server = wsgi.Server("VNC Proxy",
 
113
                         with_auth,
 
114
                         host=FLAGS.vncproxy_host,
 
115
                         port=FLAGS.vncproxy_port)
 
116
    server.start()
 
117
    server.start_tcp(handle_flash_socket_policy, 843, host=FLAGS.vncproxy_host)
 
118
 
 
119
    server.wait()