Statistics
| Branch: | Tag: | Revision:

root / ui / views.py @ b687587e

History | View | Annotate | Download (5.4 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
import os
35
from django.conf import settings
36
from django.utils.translation import gettext_lazy as _
37
from django.template import Context, loader
38
from django.http import HttpResponse
39
from django.utils.translation import get_language
40
from django.utils import simplejson as json
41
from django.shortcuts import render_to_response
42
from django.core.urlresolvers import reverse
43

    
44
TIMEOUT = settings.TIMEOUT
45
UPDATE_INTERVAL = settings.UPDATE_INTERVAL
46
IMAGE_ICONS = settings.IMAGE_ICONS
47

    
48
def template(name, context):
49
    template_path = os.path.join(os.path.dirname(__file__), "templates/")
50
    current_template = template_path + name + '.html'
51
    t = loader.get_template(current_template)
52
    return HttpResponse(t.render(Context(context)))
53

    
54
def home(request):
55
    context = {'timeout': TIMEOUT,
56
               'project': '+nefo',
57
               'request': request,
58
               'current_lang': get_language() or 'en',
59
               'update_interval': UPDATE_INTERVAL,
60
               'image_icons': IMAGE_ICONS,}
61
    return template('home', context)
62

    
63
def machines(request):
64
    context = {'default_keywords': settings.DEFAULT_KEYWORDS}
65
    return template('machines', context)
66

    
67
def machines_icon(request):
68
    context = {'default_keywords': settings.DEFAULT_KEYWORDS}
69
    return template('machines_icon', context)
70

    
71
def machines_list(request):
72
    context = {'default_keywords': settings.DEFAULT_KEYWORDS}
73
    return template('machines_list', context)
74

    
75
def machines_single(request):
76
    context = {'default_keywords': settings.DEFAULT_KEYWORDS}
77
    return template('machines_single', context)
78

    
79
def machines_console(request):
80
    host, port, password = ('','','')
81
    host = request.GET.get('host','')
82
    port = request.GET.get('port','')
83
    password = request.GET.get('password','')
84
    machine = request.GET.get('machine','')
85
    host_ip = request.GET.get('host_ip','')
86
    context = {'host': host, 'port': port, 'password': password, 'machine': machine, 'host_ip': host_ip}
87
    return template('machines_console', context)
88

    
89
def machines_connect(request):
90
    ip_address = request.GET.get('ip_address','')
91
    operating_system = request.GET.get('os','')
92
    if operating_system == 'windows' and request.GET.get("rdp", False): #check if we are on windows
93
        rdp_file = os.path.join(os.path.dirname(__file__), "static/") + 'synnefo-windows.rdp'
94
        connect_data = open(rdp_file, 'r').read()
95
        connect_data = connect_data + 'full address:s:' + ip_address + '\n'
96
        response = HttpResponse(connect_data, mimetype='application/x-rdp')
97
        response['Content-Disposition'] = 'attachment; filename=synnefo-windows.rdp'
98
    else:
99
        ssh = False
100
        if (operating_system != "windows"):
101
            ssh = True
102

    
103
        info = _("Connect on windows using the following RDP shortcut file")
104
        link_title = _("Windows RDP shortcut file")
105
        link_url = "%s?ip_address=%s&os=%s&rdp=1" % (reverse("machines-connect"), ip_address, operating_system)
106

    
107
        if (operating_system != "windows"):
108
            info = _("Connect on linux machine using the following url")
109
            link_url = "ssh://%s/" % ip_address
110
            link_title = link_url
111

    
112
        response_object = {
113
                'ip': ip_address,
114
                'os': operating_system,
115
                'ssh': ssh,
116
                'info': unicode(info),
117
                'link': {'title': unicode(link_title), 'url': link_url}
118
            }
119
        response = HttpResponse(json.dumps(response_object), mimetype='application/json')  #no windows, no rdp
120
    return response
121

    
122

    
123
def images(request):
124
    context = {}
125
    return template('images', context)
126

    
127
def disks(request):
128
    context = {}
129
    return template('disks', context)
130

    
131
def networks(request):
132
    context = {}
133
    return template('networks', context)
134

    
135
def files(request):
136
    context = {}
137
    return template('files', context)
138

    
139
def desktops(request):
140
    context = {}
141
    return template('desktops', context)
142

    
143
def apps(request):
144
    context = {}
145
    return template('apps', context)