2
# vim: tabstop=4 shiftwidth=4 softtabstop=4
4
# Copyright (c) 2010 Openstack, LLC.
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
11
# http://www.apache.org/licenses/LICENSE-2.0
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.
19
"""VNC Console Proxy Server."""
26
possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
29
if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')):
30
sys.path.insert(0, possible_topdir)
32
gettext.install('nova', unicode=1)
34
from nova import flags
35
from nova import log as logging
36
from nova import service
37
from nova import utils
39
from nova import version
40
from nova.vnc import auth
41
from nova.vnc import proxy
44
LOG = logging.getLogger('nova.vnc-proxy')
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')
61
flags.DEFINE_flag(flags.HelpFlag())
62
flags.DEFINE_flag(flags.HelpshortFlag())
63
flags.DEFINE_flag(flags.HelpXMLFlag())
66
def handle_flash_socket_policy(socket):
67
LOG.info(_("Received connection on flash socket policy port"))
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))
79
if __name__ == "__main__":
80
utils.default_flagfile()
84
LOG.audit(_("Starting nova-vnc-proxy node (version %s)"),
85
version.version_string_with_vcs())
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)
98
app = proxy.WebsocketVNCProxy(FLAGS.vncproxy_wwwroot)
100
LOG.audit(_("Allowing access to the following files: %s"),
103
with_logging = auth.LoggingMiddleware(app)
106
with_auth = proxy.DebugMiddleware(with_logging)
108
with_auth = auth.VNCNovaAuthMiddleware(with_logging)
112
server = wsgi.Server("VNC Proxy",
114
host=FLAGS.vncproxy_host,
115
port=FLAGS.vncproxy_port)
117
server.start_tcp(handle_flash_socket_policy, 843, host=FLAGS.vncproxy_host)