Statistics
| Branch: | Tag: | Revision:

root / snf-cyclades-app / synnefo / ui / views.py @ 8fa1cbc9

History | View | Annotate | Download (21 kB)

1
# Copyright 2011 GRNET S.A. All rights reserved.
2
#
3
# Redistribution and use in source and binary forms, with or
4
# without modification, are permitted provided that the following
5
# conditions are met:
6
#
7
#   1. Redistributions of source code must retain the above
8
#      copyright notice, this list of conditions and the following
9
#      disclaimer.
10
#
11
#   2. Redistributions in binary form must reproduce the above
12
#      copyright notice, this list of conditions and the following
13
#      disclaimer in the documentation and/or other materials
14
#      provided with the distribution.
15
#
16
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
# POSSIBILITY OF SUCH DAMAGE.
28
#
29
# The views and conclusions contained in the software and
30
# documentation are those of the authors and should not be
31
# interpreted as representing official policies, either expressed
32
# or implied, of GRNET S.A.
33
#
34

    
35
import os
36

    
37
from django.conf import settings
38
from django.utils.translation import gettext_lazy as _
39
from django.template import Context, loader
40
from django.http import HttpResponse
41
from django.utils.translation import get_language
42
from django.utils import simplejson as json
43
from django.shortcuts import render_to_response
44
from django.template.loader import render_to_string
45
from django.core.urlresolvers import reverse
46
from django.core.mail import send_mail
47
from django.http import Http404
48
from django.template import RequestContext
49
from synnefo_branding import settings as snf_settings
50

    
51
from synnefo.util.version import get_component_version
52

    
53
from synnefo.lib.astakos import get_user
54

    
55
SYNNEFO_JS_LIB_VERSION = get_component_version('app')
56

    
57
# api configuration
58
COMPUTE_API_URL = getattr(settings, 'COMPUTE_API_URL', '/api/v1.1')
59

    
60
# UI preferences settings
61
TIMEOUT = getattr(settings, "TIMEOUT", 10000)
62
UPDATE_INTERVAL = getattr(settings, "UI_UPDATE_INTERVAL", 5000)
63
CHANGES_SINCE_ALIGNMENT = getattr(settings, "UI_CHANGES_SINCE_ALIGNMENT", 0)
64
UPDATE_INTERVAL_INCREASE = getattr(settings, "UI_UPDATE_INTERVAL_INCREASE", 500)
65
UPDATE_INTERVAL_INCREASE_AFTER_CALLS_COUNT = getattr(settings,
66
                                "UI_UPDATE_INTERVAL_INCREASE_AFTER_CALLS_COUNT",
67
                                3)
68
UPDATE_INTERVAL_FAST = getattr(settings, "UI_UPDATE_INTERVAL_FAST", 2500)
69
UPDATE_INTERVAL_MAX = getattr(settings, "UI_UPDATE_INTERVAL_MAX", 10000)
70
QUOTAS_UPDATE_INTERVAL = getattr(settings, "UI_QUOTAS_UPDATE_INTERVAL", 10000)
71

    
72
# predefined values settings
73
VM_IMAGE_COMMON_METADATA = getattr(settings, "UI_VM_IMAGE_COMMON_METADATA", ["OS", "users"])
74
SUGGESTED_FLAVORS_DEFAULT = {}
75
SUGGESTED_FLAVORS = getattr(settings, "VM_CREATE_SUGGESTED_FLAVORS",
76
                            SUGGESTED_FLAVORS_DEFAULT)
77
SUGGESTED_ROLES_DEFAULT = ["Database server", "File server", "Mail server",
78
                           "Web server", "Proxy"]
79
SUGGESTED_ROLES = getattr(settings, "VM_CREATE_SUGGESTED_ROLES",
80
                          SUGGESTED_ROLES_DEFAULT)
81
IMAGE_ICONS = settings.IMAGE_ICONS
82
IMAGE_DELETED_TITLE = getattr(settings, 'UI_IMAGE_DELETED_TITLE',
83
                            '(deleted)')
84
IMAGE_DELETED_SIZE_TITLE = getattr(settings, 'UI_IMAGE_DELETED_SIZE_TITLE',
85
                            '(none)')
86

    
87
SUPPORT_SSH_OS_LIST = getattr(settings, "UI_SUPPORT_SSH_OS_LIST",)
88
OS_CREATED_USERS = getattr(settings, "UI_OS_DEFAULT_USER_MAP")
89
UNKNOWN_OS = getattr(settings, "UI_UNKNOWN_OS", "unknown")
90
LOGOUT_URL = getattr(settings, "UI_LOGOUT_URL", '/im/authenticate')
91
LOGIN_URL = getattr(settings, "UI_LOGIN_URL", '/im/login')
92
AUTH_COOKIE_NAME = getattr(settings, "UI_AUTH_COOKIE_NAME", 'synnefo_user')
93

    
94
# UI behaviour settings
95
DELAY_ON_BLUR = getattr(settings, "UI_DELAY_ON_BLUR", True)
96
UPDATE_HIDDEN_VIEWS = getattr(settings, "UI_UPDATE_HIDDEN_VIEWS", False)
97
HANDLE_WINDOW_EXCEPTIONS = getattr(settings, "UI_HANDLE_WINDOW_EXCEPTIONS", True)
98
SKIP_TIMEOUTS = getattr(settings, "UI_SKIP_TIMEOUTS", 1)
99

    
100
# Additional settings
101
VM_NAME_TEMPLATE = getattr(settings, "VM_CREATE_NAME_TPL", "My {0} server")
102
VM_HOSTNAME_FORMAT = getattr(settings, "UI_VM_HOSTNAME_FORMAT",
103
                                    'snf-%(id)s.vm.synnefo.org')
104

    
105
if isinstance(VM_HOSTNAME_FORMAT, basestring):
106
  VM_HOSTNAME_FORMAT =  VM_HOSTNAME_FORMAT % {'id':'{0}'}
107

    
108
MAX_SSH_KEYS_PER_USER = getattr(settings, "USERDATA_MAX_SSH_KEYS_PER_USER")
109
FLAVORS_DISK_TEMPLATES_INFO = getattr(settings, "UI_FLAVORS_DISK_TEMPLATES_INFO", {})
110
SYSTEM_IMAGES_OWNERS = getattr(settings, "UI_SYSTEM_IMAGES_OWNERS", {})
111
CUSTOM_IMAGE_HELP_URL = getattr(settings, "UI_CUSTOM_IMAGE_HELP_URL", None)
112

    
113
# MEDIA PATHS
114
UI_MEDIA_URL = getattr(settings, "UI_MEDIA_URL",
115
                    "%ssnf-%s/" % (settings.MEDIA_URL, SYNNEFO_JS_LIB_VERSION))
116
UI_SYNNEFO_IMAGES_URL = getattr(settings,
117
                    "UI_SYNNEFO_IMAGES_URL", UI_MEDIA_URL + "images/")
118
UI_SYNNEFO_CSS_URL = getattr(settings,
119
                    "UI_SYNNEFO_CSS_URL", UI_MEDIA_URL + "css/")
120
UI_SYNNEFO_JS_URL = getattr(settings,
121
                    "UI_SYNNEFO_JS_URL", UI_MEDIA_URL + "js/")
122
UI_SYNNEFO_JS_LIB_URL = getattr(settings,
123
                    "UI_SYNNEFO_JS_LIB_URL", UI_SYNNEFO_JS_URL + "lib/")
124
UI_SYNNEFO_JS_WEB_URL = getattr(settings,
125
                    "UI_SYNNEFO_JS_WEB_URL",
126
                    UI_SYNNEFO_JS_URL + "ui/web/")
127

    
128
# extensions
129
ENABLE_GLANCE = getattr(settings, 'UI_ENABLE_GLANCE', True)
130
GLANCE_API_URL = getattr(settings, 'UI_GLANCE_API_URL', '/glance')
131
FEEDBACK_CONTACTS = getattr(settings, "FEEDBACK_CONTACTS", [])
132
DIAGNOSTICS_UPDATE_INTERVAL = getattr(settings,
133
                'UI_DIAGNOSTICS_UPDATE_INTERVAL', 2000)
134

    
135
# network settings
136
DEFAULT_NETWORK_TYPES = {'MAC_FILTERED': 'mac-filtering', 'PHYSICAL_VLAN': 'physical-vlan'}
137
NETWORK_TYPES = getattr(settings,
138
                    'UI_NETWORK_AVAILABLE_NETWORK_TYPES', DEFAULT_NETWORK_TYPES)
139
DEFAULT_NETWORK_SUBNETS = ['10.0.0.0/24', '192.168.1.1/24']
140
NETWORK_SUBNETS = getattr(settings,
141
                    'UI_NETWORK_AVAILABLE_SUBNETS', DEFAULT_NETWORK_SUBNETS)
142
NETWORK_DUPLICATE_NICS = getattr(settings,
143
                    'UI_NETWORK_ALLOW_DUPLICATE_VM_NICS', False)
144
NETWORK_STRICT_DESTROY = getattr(settings,
145
                    'UI_NETWORK_STRICT_DESTROY', False)
146
NETWORK_ALLOW_MULTIPLE_DESTROY = getattr(settings,
147
                    'UI_NETWORK_ALLOW_MULTIPLE_DESTROY', False)
148
AUTOMATIC_NETWORK_RANGE_FORMAT = getattr(settings,
149
                                         'UI_AUTOMATIC_NETWORK_RANGE_FORMAT',
150
                                        "192.168.%d.0/24").replace("%d", "{0}")
151
GROUP_PUBLIC_NETWORKS = getattr(settings, 'UI_GROUP_PUBLIC_NETWORKS', True)
152
GROUPED_PUBLIC_NETWORK_NAME = getattr(settings, 'UI_GROUPED_PUBLIC_NETWORK_NAME', 'Internet')
153

    
154
USER_CATALOG_URL = getattr(settings, 'UI_USER_CATALOG_URL', '/user_catalogs')
155
TRANSLATE_UUIDS = not getattr(settings, 'TRANSLATE_UUIDS', False)
156

    
157
def template(name, request, context):
158
    template_path = os.path.join(os.path.dirname(__file__), "templates/")
159
    current_template = template_path + name + '.html'
160
    t = loader.get_template(current_template)
161
    media_context = {
162
       'UI_MEDIA_URL': UI_MEDIA_URL,
163
       'SYNNEFO_JS_URL': UI_SYNNEFO_JS_URL,
164
       'SYNNEFO_JS_LIB_URL': UI_SYNNEFO_JS_LIB_URL,
165
       'SYNNEFO_JS_WEB_URL': UI_SYNNEFO_JS_WEB_URL,
166
       'SYNNEFO_IMAGES_URL': UI_SYNNEFO_IMAGES_URL,
167
       'SYNNEFO_CSS_URL': UI_SYNNEFO_CSS_URL,
168
       'SYNNEFO_JS_LIB_VERSION': SYNNEFO_JS_LIB_VERSION,
169
       'DEBUG': settings.DEBUG
170
    }
171
    context.update(media_context)
172
    return HttpResponse(t.render(RequestContext(request, context)))
173

    
174
def home(request):
175
    context = {'timeout': TIMEOUT,
176
               'project': '+nefo',
177
               'request': request,
178
               'current_lang': get_language() or 'en',
179
               'compute_api_url': json.dumps(COMPUTE_API_URL),
180
               'user_catalog_url': json.dumps(USER_CATALOG_URL),
181
               'translate_uuids': json.dumps(TRANSLATE_UUIDS),
182
                # update interval settings
183
               'update_interval': UPDATE_INTERVAL,
184
               'update_interval_increase': UPDATE_INTERVAL_INCREASE,
185
               'update_interval_increase_after_calls': UPDATE_INTERVAL_INCREASE_AFTER_CALLS_COUNT,
186
               'update_interval_fast': UPDATE_INTERVAL_FAST,
187
               'update_interval_max': UPDATE_INTERVAL_MAX,
188
               'changes_since_alignment': CHANGES_SINCE_ALIGNMENT,
189
               'quotas_update_interval': QUOTAS_UPDATE_INTERVAL,
190
                # additional settings
191
               'image_icons': IMAGE_ICONS,
192
               'logout_redirect': LOGOUT_URL,
193
               'login_redirect': LOGIN_URL,
194
               'auth_cookie_name': AUTH_COOKIE_NAME,
195
               'suggested_flavors': json.dumps(SUGGESTED_FLAVORS),
196
               'suggested_roles': json.dumps(SUGGESTED_ROLES),
197
               'vm_image_common_metadata': json.dumps(VM_IMAGE_COMMON_METADATA),
198
               'synnefo_version': SYNNEFO_JS_LIB_VERSION,
199
               'delay_on_blur': json.dumps(DELAY_ON_BLUR),
200
               'update_hidden_views': json.dumps(UPDATE_HIDDEN_VIEWS),
201
               'handle_window_exceptions': json.dumps(HANDLE_WINDOW_EXCEPTIONS),
202
               'skip_timeouts': json.dumps(SKIP_TIMEOUTS),
203
               'vm_name_template': json.dumps(VM_NAME_TEMPLATE),
204
               'flavors_disk_templates_info': json.dumps(FLAVORS_DISK_TEMPLATES_INFO),
205
               'support_ssh_os_list': json.dumps(SUPPORT_SSH_OS_LIST),
206
               'os_created_users': json.dumps(OS_CREATED_USERS),
207
               'unknown_os': json.dumps(UNKNOWN_OS),
208
               'userdata_keys_limit': json.dumps(MAX_SSH_KEYS_PER_USER),
209
               'use_glance': json.dumps(ENABLE_GLANCE),
210
               'glance_api_url': json.dumps(GLANCE_API_URL),
211
               'system_images_owners': json.dumps(SYSTEM_IMAGES_OWNERS),
212
               'custom_image_help_url': CUSTOM_IMAGE_HELP_URL,
213
               'image_deleted_title': json.dumps(IMAGE_DELETED_TITLE),
214
               'image_deleted_size_title': json.dumps(IMAGE_DELETED_SIZE_TITLE),
215
               'network_suggested_subnets': json.dumps(NETWORK_SUBNETS),
216
               'network_available_types': json.dumps(NETWORK_TYPES),
217
               'network_allow_duplicate_vm_nics': json.dumps(NETWORK_DUPLICATE_NICS),
218
               'network_strict_destroy': json.dumps(NETWORK_STRICT_DESTROY),
219
               'network_allow_multiple_destroy': json.dumps(NETWORK_ALLOW_MULTIPLE_DESTROY),
220
               'automatic_network_range_format': json.dumps(AUTOMATIC_NETWORK_RANGE_FORMAT),
221
               'grouped_public_network_name': json.dumps(GROUPED_PUBLIC_NETWORK_NAME),
222
               'group_public_networks': json.dumps(GROUP_PUBLIC_NETWORKS),
223
               'diagnostics_update_interval': json.dumps(DIAGNOSTICS_UPDATE_INTERVAL),
224
               'vm_hostname_format': json.dumps(VM_HOSTNAME_FORMAT)
225
    }
226
    return template('home', request, context)
227

    
228
def machines_console(request):
229
    host, port, password = ('','','')
230
    host = request.GET.get('host','')
231
    port = request.GET.get('port','')
232
    password = request.GET.get('password','')
233
    machine = request.GET.get('machine','')
234
    host_ip = request.GET.get('host_ip','')
235
    host_ip_v6 = request.GET.get('host_ip_v6','')
236
    context = {'host': host, 'port': port, 'password': password,
237
               'machine': machine, 'host_ip': host_ip, 'host_ip_v6': host_ip_v6}
238
    return template('machines_console', request, context)
239

    
240
def user_quota(request):
241
    try:
242
        get_user(request, settings.ASTAKOS_URL, usage=True)
243
    except TypeError:
244
        # astakos client backwards compatibility
245
        get_user(request, settings.ASTAKOS_URL)
246

    
247
    vms_limit_for_user = \
248
        settings.VMS_USER_QUOTA.get(request.user_uniq,
249
                settings.MAX_VMS_PER_USER)
250

    
251
    networks_limit_for_user = \
252
        settings.NETWORKS_USER_QUOTA.get(request.user_uniq,
253
                settings.MAX_NETWORKS_PER_USER)
254

    
255
    if request.user and 'usage' in request.user:
256
        quota = dict(zip([q['name'] for q in request.user['usage']],
257
                         request.user['usage']))
258

    
259
        # TODO: is it ok to use hardcoded resource name ???
260
        if 'cyclades.vm' in quota:
261
            vms_limit_for_user = quota['cyclades.vm']['maxValue']
262
        if 'cyclades.network.private' in quota:
263
            networks_limit_for_user = quota['cyclades.network.private']['maxValue']
264

    
265
    return HttpResponse('{"vms_quota":%d, "networks_quota":%d}' % (vms_limit_for_user,
266
                                                               networks_limit_for_user),
267
                        mimetype="application/json")
268

    
269
def js_tests(request):
270
    return template('tests', request, {})
271

    
272
CONNECT_LINUX_LINUX_MESSAGE = _("""A direct connection to this machine can be established using the <a target="_blank"
273
href="http://en.wikipedia.org/wiki/Secure_Shell">SSH Protocol</a>.
274
To do so open a terminal and type the following at the prompt to connect to your machine:""")
275
CONNECT_LINUX_WINDOWS_MESSAGE = _("""A direct connection to this machine can be
276
established using <a target="_blank" href="http://en.wikipedia.org/wiki/Remote_Desktop_Services">Remote Desktop Service</a>.
277
To do so, open the following file with an appropriate remote desktop client.
278
""")
279
CONNECT_LINUX_WINDOWS_SUBMESSAGE = _("""If you don't have a Remote Desktop client already installed,
280
we suggest the use of <a target="_blank"
281
href="http://sourceforge.net/projects/tsclient/files/latest/download?source=files">tsclient</a>.<br
282
/><span class="important">IMPORTANT: It may take up to 15 minutes for your Windows VM to become available
283
after its creation.</span>""")
284
CONNECT_WINDOWS_LINUX_MESSAGE = _("""A direct connection to this machine can be established using the <a target="_blank"
285
href="http://en.wikipedia.org/wiki/Secure_Shell">SSH Protocol</a>.
286
Open an ssh client such as PuTTY and type the following:""")
287
CONNECT_WINDOWS_LINUX_SUBMESSAGE = _("""If you do not have an ssh client already installed,
288
<a target="_blank" href="http://the.earth.li/~sgtatham/putty/latest/x86/putty.exe">Download PuTTY</a>""")
289

    
290
CONNECT_WINDOWS_WINDOWS_MESSAGE = _("""A direct connection to this machine can be
291
established using Remote Desktop. Click on the following link, and if asked
292
open it using "Remote Desktop Connection".
293
<br /><span class="important">IMPORTANT: It may take up to 15 minutes for your Windows VM to become available
294
after its creation.</span>""")
295
CONNECT_WINDOWS_WINDOWS_SUBMESSAGE = _("""Save this file to disk for future use.""")
296

    
297
# info/subinfo for all os combinations
298
#
299
# [0] info gets displayed on top of the message box
300
# [1] subinfo gets displayed on the bottom as extra info
301
# provided to the user when needed
302
CONNECT_PROMPT_MESSAGES = {
303
    'linux': {
304
            'linux': [CONNECT_LINUX_LINUX_MESSAGE, ""],
305
            'windows': [CONNECT_LINUX_WINDOWS_MESSAGE,
306
                        CONNECT_LINUX_WINDOWS_SUBMESSAGE],
307
            'ssh_message': "ssh %(user)s@%(hostname)s"
308
    },
309
    'windows': {
310
            'linux': [CONNECT_WINDOWS_LINUX_MESSAGE,
311
                      CONNECT_WINDOWS_LINUX_SUBMESSAGE],
312
            'windows': [CONNECT_WINDOWS_WINDOWS_MESSAGE,
313
                        CONNECT_WINDOWS_WINDOWS_SUBMESSAGE],
314
            'ssh_message': "%(user)s@%(hostname)s"
315
    },
316
}
317

    
318
APPEND_CONNECT_PROMPT_MESSAGES = getattr(settings, 'UI_CONNECT_PROMPT_MESSAGES',
319
                                       {})
320
for k, v in APPEND_CONNECT_PROMPT_MESSAGES.iteritems():
321
    CONNECT_PROMPT_MESSAGES[k].update(v)
322

    
323
# retrieve domain prefix from settings
324
DOMAIN_PREFIX = getattr(settings, 'MACHINE_DOMAIN_PREFIX', getattr(settings,
325
                        'BACKEND_PREFIX_ID', ""))
326

    
327
# domain template string
328
DOMAIN_TPL = "%s%%s" % DOMAIN_PREFIX
329

    
330
def machines_connect(request):
331
    ip_address = request.GET.get('ip_address','')
332
    hostname = request.GET.get('hostname','')
333
    operating_system = metadata_os = request.GET.get('os','')
334
    server_id = request.GET.get('srv', 0)
335
    host_os = request.GET.get('host_os','Linux').lower()
336
    username = request.GET.get('username', None)
337
    domain = request.GET.get("domain", DOMAIN_TPL % int(server_id))
338

    
339
    # guess host os
340
    if host_os != "windows":
341
        host_os = 'linux'
342

    
343
    # guess username
344
    if not username:
345
        username = "root"
346

    
347
        if metadata_os.lower() in ['ubuntu', 'kubuntu', 'fedora']:
348
            username = "user"
349

    
350
        if metadata_os.lower() == "windows":
351
            username = "Administrator"
352

    
353
    # operating system provides ssh access
354
    ssh = False
355
    if operating_system != "windows":
356
        operating_system = "linux"
357
        ssh = True
358

    
359
    # rdp param is set, the user requested rdp file
360
    # check if we are on windows
361
    if operating_system == 'windows' and request.GET.get("rdp", False):
362

    
363
        # UI sent domain info (from vm metadata) use this
364
        # otherwise use our default snf-<vm_id> domain
365
        EXTRA_RDP_CONTENT = getattr(settings, 'UI_EXTRA_RDP_CONTENT', '')
366
        if callable(EXTRA_RDP_CONTENT):
367
            extra_rdp_content = EXTRA_RDP_CONTENT(server_id, ip_address,
368
                                                  hostname, username)
369
        else:
370
            extra_rdp_content = EXTRA_RDP_CONTENT % {
371
                    'server_id':server_id,
372
                    'ip_address': ip_address,
373
                    'hostname': hostname,
374
                    'user': username
375
                  }
376

    
377
        rdp_context = {
378
                'username': username,
379
                'domain': domain,
380
                'ip_address': ip_address,
381
                'hostname': hostname,
382
                'extra_content': extra_rdp_content
383
        }
384

    
385
        rdp_file_data = render_to_string("synnefo-windows.rdp", rdp_context)
386
        response = HttpResponse(rdp_file_data, mimetype='application/x-rdp')
387

    
388
        # proper filename, use server id and ip address
389
        filename = "%d-%s.rdp" % (int(server_id), hostname)
390
        response['Content-Disposition'] = 'attachment; filename=%s' % filename
391
    else:
392
        ssh_message = CONNECT_PROMPT_MESSAGES['linux'].get('ssh_message')
393
        if host_os == 'windows':
394
            ssh_message = CONNECT_PROMPT_MESSAGES['windows'].get('ssh_message')
395
        if callable(ssh_message):
396
            link_title = ssh_message(server_id, ip_address, hostname, username)
397
        else:
398
            link_title = ssh_message % {
399
                    'server_id':server_id,
400
                    'ip_address': ip_address,
401
                    'hostname': hostname,
402
                    'user': username
403
                  }
404
        if (operating_system != "windows"):
405
            link_url = None
406

    
407
        else:
408
            link_title = _("Remote desktop to %s") % ip_address
409
            link_url = "%s?ip_address=%s&os=%s&rdp=1&srv=%d&username=%s&domain=%s&hostname=%s" % (
410
                    reverse("ui_machines_connect"), ip_address,
411
                    operating_system, int(server_id), username, domain, hostname)
412

    
413
        # try to find a specific message
414
        try:
415
            connect_message = CONNECT_PROMPT_MESSAGES[host_os][operating_system][0]
416
            subinfo = CONNECT_PROMPT_MESSAGES[host_os][operating_system][1]
417
        except KeyError:
418
            connect_message = _("You are trying to connect from a %(host_os)s "
419
                                "machine to a %(os)s machine") % dict(host_os=host_os, os=operating_system)
420
            subinfo = ""
421

    
422
        response_object = {
423
                'ip': ip_address,
424
                'os': operating_system,
425
                'ssh': ssh,
426
                'info': unicode(connect_message),
427
                'subinfo': unicode(subinfo),
428
                'link': {'title': unicode(link_title), 'url': link_url}
429
            }
430
        response = HttpResponse(json.dumps(response_object),
431
                                mimetype='application/json')  #no windows, no rdp
432

    
433
    return response
434

    
435
def feedback_submit(request):
436
    if not request.method == "POST":
437
        raise Http404
438

    
439
    # fill request object with astakos user information
440
    get_user(request, settings.ASTAKOS_URL)
441

    
442
    message = request.POST.get("feedback-msg")
443
    data = request.POST.get("feedback-data")
444
    if isinstance(request.user.get('email'), list):
445
        email = request.user.get('email')[0]
446
    else:
447
        email = request.user.get('email')
448

    
449
    # default to True (calls from error pages)
450
    allow_data_send = request.POST.get("feedback-submit-data", True)
451

    
452
    mail_subject_txt = 'Feedback from '
453
    + snf_settings.BRANDING_SERVICE_NAME +' application'
454
    mail_subject = unicode(_mail_subject_txt)
455

    
456
    mail_context = {'message': message, 'data': data, 'email': email,
457
                    'allow_data_send': allow_data_send, 'request': request}
458
    mail_content = render_to_string("feedback_mail.txt", mail_context)
459

    
460
    send_mail(mail_subject, mail_content, FEEDBACK_EMAIL_FROM,
461
              dict(FEEDBACK_CONTACTS).values(), fail_silently=False)
462

    
463
    return HttpResponse('{"status":"send"}')