Statistics
| Branch: | Tag: | Revision:

root / snf-cyclades-app / synnefo / ui / views.py @ 73e4a52a

History | View | Annotate | Download (20.2 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

    
50
from synnefo.util.version import get_component_version
51

    
52
from synnefo.lib.astakos import get_user
53

    
54
SYNNEFO_JS_LIB_VERSION = get_component_version('app')
55

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

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

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

    
85
SUPPORT_SSH_OS_LIST = getattr(settings, "UI_SUPPORT_SSH_OS_LIST",)
86
OS_CREATED_USERS = getattr(settings, "UI_OS_DEFAULT_USER_MAP")
87
LOGOUT_URL = getattr(settings, "UI_LOGOUT_URL", '/im/authenticate')
88
LOGIN_URL = getattr(settings, "UI_LOGIN_URL", '/im/login')
89
AUTH_COOKIE_NAME = getattr(settings, "UI_AUTH_COOKIE_NAME", 'synnefo_user')
90

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

    
97
# Additional settings
98
VM_NAME_TEMPLATE = getattr(settings, "VM_CREATE_NAME_TPL", "My {0} server")
99
VM_HOSTNAME_FORMAT = getattr(settings, "UI_VM_HOSTNAME_FORMAT",
100
                                    'snf-%(id)s.vm.okeanos.grnet.gr')
101

    
102
if isinstance(VM_HOSTNAME_FORMAT, basestring):
103
  VM_HOSTNAME_FORMAT =  VM_HOSTNAME_FORMAT % {'id':'{0}'}
104

    
105
MAX_SSH_KEYS_PER_USER = getattr(settings, "USERDATA_MAX_SSH_KEYS_PER_USER")
106
FLAVORS_DISK_TEMPLATES_INFO = getattr(settings, "UI_FLAVORS_DISK_TEMPLATES_INFO", {})
107
SYSTEM_IMAGES_OWNERS = getattr(settings, "UI_SYSTEM_IMAGES_OWNERS", {})
108
CUSTOM_IMAGE_HELP_URL = getattr(settings, "UI_CUSTOM_IMAGE_HELP_URL", None)
109

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

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

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

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

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

    
219
def machines_console(request):
220
    host, port, password = ('','','')
221
    host = request.GET.get('host','')
222
    port = request.GET.get('port','')
223
    password = request.GET.get('password','')
224
    machine = request.GET.get('machine','')
225
    host_ip = request.GET.get('host_ip','')
226
    host_ip_v6 = request.GET.get('host_ip_v6','')
227
    context = {'host': host, 'port': port, 'password': password,
228
               'machine': machine, 'host_ip': host_ip, 'host_ip_v6': host_ip_v6}
229
    return template('machines_console', request, context)
230

    
231
def user_quota(request):
232
    try:
233
        get_user(request, settings.ASTAKOS_URL, usage=True)
234
    except TypeError:
235
        # astakos client backwards compatibility
236
        get_user(request, settings.ASTAKOS_URL)
237

    
238
    vms_limit_for_user = \
239
        settings.VMS_USER_QUOTA.get(request.user_uniq,
240
                settings.MAX_VMS_PER_USER)
241

    
242
    networks_limit_for_user = \
243
        settings.NETWORKS_USER_QUOTA.get(request.user_uniq,
244
                settings.MAX_NETWORKS_PER_USER)
245

    
246
    if 'usage' in request.user:
247
        quota = dict(zip([q['name'] for q in request.user['usage']],
248
                         request.user['usage']))
249

    
250
        # TODO: is it ok to use hardcoded resource name ???
251
        if 'cyclades.vm' in quota:
252
            vms_limit_for_user = quota['cyclades.vm']['maxValue']
253
        if 'cyclades.network.private' in quota:
254
            networks_limit_for_user = quota['cyclades.network.private']['maxValue']
255

    
256
    return HttpResponse('{"vms_quota":%d, "networks_quota":%d}' % (vms_limit_for_user,
257
                                                               networks_limit_for_user),
258
                        mimetype="application/json")
259

    
260
def js_tests(request):
261
    return template('tests', request, {})
262

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

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

    
288
# info/subinfo for all os combinations
289
#
290
# [0] info gets displayed on top of the message box
291
# [1] subinfo gets displayed on the bottom as extra info
292
# provided to the user when needed
293
CONNECT_PROMPT_MESSAGES = {
294
    'linux': {
295
            'linux': [CONNECT_LINUX_LINUX_MESSAGE, ""],
296
            'windows': [CONNECT_LINUX_WINDOWS_MESSAGE,
297
                        CONNECT_LINUX_WINDOWS_SUBMESSAGE],
298
            'ssh_message': "ssh %(user)s@%(hostname)s"
299
    },
300
    'windows': {
301
            'linux': [CONNECT_WINDOWS_LINUX_MESSAGE,
302
                      CONNECT_WINDOWS_LINUX_SUBMESSAGE],
303
            'windows': [CONNECT_WINDOWS_WINDOWS_MESSAGE,
304
                        CONNECT_WINDOWS_WINDOWS_SUBMESSAGE],
305
            'ssh_message': "%(user)s@%(hostname)s"
306
    },
307
}
308

    
309
APPEND_CONNECT_PROMPT_MESSAGES = getattr(settings, 'UI_CONNECT_PROMPT_MESSAGES',
310
                                       {})
311
for k, v in APPEND_CONNECT_PROMPT_MESSAGES.iteritems():
312
    CONNECT_PROMPT_MESSAGES[k].update(v)
313

    
314
# retrieve domain prefix from settings
315
DOMAIN_PREFIX = getattr(settings, 'MACHINE_DOMAIN_PREFIX', getattr(settings,
316
                        'BACKEND_PREFIX_ID', ""))
317

    
318
# domain template string
319
DOMAIN_TPL = "%s%%s" % DOMAIN_PREFIX
320

    
321
def machines_connect(request):
322
    ip_address = request.GET.get('ip_address','')
323
    hostname = request.GET.get('hostname','')
324
    operating_system = metadata_os = request.GET.get('os','')
325
    server_id = request.GET.get('srv', 0)
326
    host_os = request.GET.get('host_os','Linux').lower()
327
    username = request.GET.get('username', None)
328
    domain = request.GET.get("domain", DOMAIN_TPL % int(server_id))
329

    
330
    # guess host os
331
    if host_os != "windows":
332
        host_os = 'linux'
333

    
334
    # guess username
335
    if not username:
336
        username = "root"
337

    
338
        if metadata_os.lower() in ['ubuntu', 'kubuntu', 'fedora']:
339
            username = "user"
340

    
341
        if metadata_os.lower() == "windows":
342
            username = "Administrator"
343

    
344
    # operating system provides ssh access
345
    ssh = False
346
    if operating_system != "windows":
347
        operating_system = "linux"
348
        ssh = True
349

    
350
    # rdp param is set, the user requested rdp file
351
    # check if we are on windows
352
    if operating_system == 'windows' and request.GET.get("rdp", False):
353

    
354
        # UI sent domain info (from vm metadata) use this
355
        # otherwise use our default snf-<vm_id> domain
356
        EXTRA_RDP_CONTENT = getattr(settings, 'UI_EXTRA_RDP_CONTENT', '')
357
        if callable(EXTRA_RDP_CONTENT):
358
            extra_rdp_content = EXTRA_RDP_CONTENT(server_id, ip_address,
359
                                                  hostname, username)
360
        else:
361
            extra_rdp_content = EXTRA_RDP_CONTENT % {
362
                    'server_id':server_id,
363
                    'ip_address': ip_address,
364
                    'hostname': hostname,
365
                    'user': username
366
                  }
367

    
368
        rdp_context = {
369
                'username': username,
370
                'domain': domain,
371
                'ip_address': ip_address,
372
                'hostname': hostname,
373
                'extra_content': extra_rdp_content
374
        }
375

    
376
        rdp_file_data = render_to_string("synnefo-windows.rdp", rdp_context)
377
        response = HttpResponse(rdp_file_data, mimetype='application/x-rdp')
378

    
379
        # proper filename, use server id and ip address
380
        filename = "%d-%s.rdp" % (int(server_id), hostname)
381
        response['Content-Disposition'] = 'attachment; filename=%s' % filename
382
    else:
383
        ssh_message = CONNECT_PROMPT_MESSAGES['linux'].get('ssh_message')
384
        if host_os == 'windows':
385
            ssh_message = CONNECT_PROMPT_MESSAGES['windows'].get('ssh_message')
386
        if callable(ssh_message):
387
            link_title = ssh_message(server_id, ip_address, hostname, username)
388
        else:
389
            link_title = ssh_message % {
390
                    'server_id':server_id,
391
                    'ip_address': ip_address,
392
                    'hostname': hostname,
393
                    'user': username
394
                  }
395
        if (operating_system != "windows"):
396
            link_url = None
397

    
398
        else:
399
            link_title = _("Remote desktop to %s") % ip_address
400
            link_url = "%s?ip_address=%s&os=%s&rdp=1&srv=%d&username=%s&domain=%s&hostname=%s" % (
401
                    reverse("ui_machines_connect"), ip_address,
402
                    operating_system, int(server_id), username, domain, hostname)
403

    
404
        # try to find a specific message
405
        try:
406
            connect_message = CONNECT_PROMPT_MESSAGES[host_os][operating_system][0]
407
            subinfo = CONNECT_PROMPT_MESSAGES[host_os][operating_system][1]
408
        except KeyError:
409
            connect_message = _("You are trying to connect from a %s "
410
                                "machine to a %s machine") % (host_os, operating_system)
411
            subinfo = ""
412

    
413
        response_object = {
414
                'ip': ip_address,
415
                'os': operating_system,
416
                'ssh': ssh,
417
                'info': unicode(connect_message),
418
                'subinfo': unicode(subinfo),
419
                'link': {'title': unicode(link_title), 'url': link_url}
420
            }
421
        response = HttpResponse(json.dumps(response_object),
422
                                mimetype='application/json')  #no windows, no rdp
423

    
424
    return response
425

    
426
def feedback_submit(request):
427
    if not request.method == "POST":
428
        raise Http404
429

    
430
    # fill request object with astakos user information
431
    get_user(request, settings.ASTAKOS_URL)
432

    
433
    message = request.POST.get("feedback-msg")
434
    data = request.POST.get("feedback-data")
435

    
436
    # default to True (calls from error pages)
437
    allow_data_send = request.POST.get("feedback-submit-data", True)
438

    
439
    mail_subject = unicode(_("Feedback from synnefo application"))
440

    
441
    mail_context = {'message': message, 'data': data,
442
                    'allow_data_send': allow_data_send, 'request': request}
443
    mail_content = render_to_string("feedback_mail.txt", mail_context)
444

    
445
    send_mail(mail_subject, mail_content, FEEDBACK_EMAIL_FROM,
446
            dict(FEEDBACK_CONTACTS).values(), fail_silently=False)
447

    
448
    return HttpResponse('{"status":"send"}');
449