root / ui / views.py @ fea36bdb
History | View | Annotate | Download (9.7 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.template.loader import render_to_string |
43 |
from django.core.urlresolvers import reverse |
44 |
|
45 |
from synnefo.logic.email_send import send_async |
46 |
|
47 |
from django.http import Http404 |
48 |
|
49 |
TIMEOUT = settings.TIMEOUT |
50 |
UPDATE_INTERVAL = settings.UPDATE_INTERVAL |
51 |
IMAGE_ICONS = settings.IMAGE_ICONS |
52 |
LOGOUT_URL = getattr(settings, "LOGOUT_URL", settings.LOGIN_URL) |
53 |
|
54 |
def template(name, context): |
55 |
template_path = os.path.join(os.path.dirname(__file__), "templates/")
|
56 |
current_template = template_path + name + '.html'
|
57 |
t = loader.get_template(current_template) |
58 |
return HttpResponse(t.render(Context(context)))
|
59 |
|
60 |
def home(request): |
61 |
context = {'timeout': TIMEOUT,
|
62 |
'project': '+nefo', |
63 |
'request': request,
|
64 |
'current_lang': get_language() or 'en', |
65 |
'update_interval': UPDATE_INTERVAL,
|
66 |
'image_icons': IMAGE_ICONS,
|
67 |
'logout_redirect': LOGOUT_URL,
|
68 |
'DEBUG': settings.DEBUG}
|
69 |
return template('home', context) |
70 |
|
71 |
def machines(request): |
72 |
context = {'default_keywords': settings.DEFAULT_KEYWORDS}
|
73 |
return template('machines', context) |
74 |
|
75 |
def machines_icon(request): |
76 |
context = {'default_keywords': settings.DEFAULT_KEYWORDS}
|
77 |
return template('machines_icon', context) |
78 |
|
79 |
def machines_list(request): |
80 |
context = {'default_keywords': settings.DEFAULT_KEYWORDS}
|
81 |
return template('machines_list', context) |
82 |
|
83 |
def machines_single(request): |
84 |
context = {'default_keywords': settings.DEFAULT_KEYWORDS}
|
85 |
return template('machines_single', context) |
86 |
|
87 |
def machines_console(request): |
88 |
host, port, password = ('','','') |
89 |
host = request.GET.get('host','') |
90 |
port = request.GET.get('port','') |
91 |
password = request.GET.get('password','') |
92 |
machine = request.GET.get('machine','') |
93 |
host_ip = request.GET.get('host_ip','') |
94 |
host_ip_v6 = request.GET.get('host_ip_v6','') |
95 |
context = {'host': host, 'port': port, 'password': password, 'machine': machine, 'host_ip': host_ip, 'host_ip_v6': host_ip_v6} |
96 |
return template('machines_console', context) |
97 |
|
98 |
|
99 |
CONNECT_LINUX_LINUX_MESSAGE = _("""A direct connection to this machine can be established using the <a target="_blank"
|
100 |
href="http://en.wikipedia.org/wiki/Secure_Shell">SSH Protocol</a>.
|
101 |
To do so open a terminal and type the following at the prompt to connect to your machine:""")
|
102 |
CONNECT_LINUX_WINDOWS_MESSAGE = _("""A direct connection to this machine can be
|
103 |
established using <a target="_blank" href="http://en.wikipedia.org/wiki/Remote_Desktop_Services">Remote Desktop Service</a>.
|
104 |
To do so, open the following file with an appropriate remote desktop client.""")
|
105 |
CONNECT_LINUX_WINDOWS_SUBMESSAGE = _("""If you don't have one already
|
106 |
installed, we suggest the use of <a target="_blank" href="http://sourceforge.net/projects/tsclient/files/tsclient/tsclient-unstable/tsclient-2.0.1.tar.bz2/download">tsclient</a>.""")
|
107 |
|
108 |
CONNECT_WINDOWS_LINUX_MESSAGE = _("""A direct connection to this machine can be established using the <a target="_blank"
|
109 |
href="http://en.wikipedia.org/wiki/Secure_Shell">SSH Protocol</a>.
|
110 |
Open an ssh client such as PuTTY and type the following:""")
|
111 |
CONNECT_WINDOWS_LINUX_SUBMESSAGE = _("""If you do not have an ssh client already installed,
|
112 |
<a target="_blank" href="http://the.earth.li/~sgtatham/putty/latest/x86/putty.exe">Download PuTTY</a>""")
|
113 |
CONNECT_WINDOWS_WINDOWS_MESSAGE = _("Trying to connect from windows to windows")
|
114 |
|
115 |
|
116 |
# info/subinfo for all os combinations
|
117 |
#
|
118 |
# [0] info gets displayed on top of the message box
|
119 |
# [1] subinfo gets displayed on the bottom as extra info
|
120 |
# provided to the user when needed
|
121 |
CONNECT_PROMT_MESSAGES = { |
122 |
'linux': {
|
123 |
'linux': [CONNECT_LINUX_LINUX_MESSAGE, ""], |
124 |
'windows': [CONNECT_LINUX_WINDOWS_MESSAGE, CONNECT_LINUX_WINDOWS_SUBMESSAGE]
|
125 |
}, |
126 |
'windows': {
|
127 |
'linux': [CONNECT_WINDOWS_LINUX_MESSAGE, CONNECT_WINDOWS_LINUX_SUBMESSAGE],
|
128 |
'windows': [CONNECT_WINDOWS_WINDOWS_MESSAGE, ""] |
129 |
} |
130 |
} |
131 |
|
132 |
def machines_connect(request): |
133 |
ip_address = request.GET.get('ip_address','') |
134 |
operating_system = metadata_os = request.GET.get('os','') |
135 |
server_id = request.GET.get('srv', 0) |
136 |
host_os = request.GET.get('host_os','Linux').lower() |
137 |
username = request.GET.get('username', None) |
138 |
|
139 |
if operating_system != "windows": |
140 |
operating_system = "linux"
|
141 |
|
142 |
# rdp param is set, the user requested rdp file
|
143 |
if operating_system == 'windows' and request.GET.get("rdp", False): #check if we are on windows |
144 |
rdp_file = os.path.join(os.path.dirname(__file__), "static/") + 'synnefo-windows.rdp' |
145 |
connect_data = open(rdp_file, 'r').read() |
146 |
connect_data = connect_data + 'full address:s:' + ip_address + '\n' |
147 |
response = HttpResponse(connect_data, mimetype='application/x-rdp')
|
148 |
|
149 |
# proper filename, use server id and ip address
|
150 |
filename = "%d-%s.rdp" % (int(server_id), ip_address) |
151 |
response['Content-Disposition'] = 'attachment; filename=%s' % filename |
152 |
else:
|
153 |
# no rdp requested return json object with info on how to connect
|
154 |
ssh = False
|
155 |
if (operating_system != "windows"): |
156 |
ssh = True
|
157 |
|
158 |
link_title = _("Remote desktop to %s") % ip_address
|
159 |
link_url = "%s?ip_address=%s&os=%s&rdp=1&srv=%d" % (reverse("machines-connect"), ip_address, operating_system, |
160 |
int(server_id))
|
161 |
|
162 |
user = username |
163 |
if not user: |
164 |
user = "root"
|
165 |
if metadata_os.lower() in ['ubuntu', 'kubuntu', 'fedora']: |
166 |
user = "user"
|
167 |
|
168 |
if (operating_system != "windows"): |
169 |
link_title = "ssh %s@%s" % (user, ip_address)
|
170 |
link_url = None
|
171 |
|
172 |
if host_os == "windows": |
173 |
link_title = "%s@%s" % (user, ip_address)
|
174 |
|
175 |
# try to find a specific message
|
176 |
try:
|
177 |
connect_message = CONNECT_PROMT_MESSAGES[host_os][operating_system][0]
|
178 |
subinfo = CONNECT_PROMT_MESSAGES[host_os][operating_system][1]
|
179 |
except KeyError: |
180 |
connect_message = _("You are trying to connect from a %s machine to a %s machine") % (host_os, operating_system)
|
181 |
subinfo = ""
|
182 |
|
183 |
response_object = { |
184 |
'ip': ip_address,
|
185 |
'os': operating_system,
|
186 |
'ssh': ssh,
|
187 |
'info': unicode(connect_message), |
188 |
'subinfo': unicode(subinfo), |
189 |
'link': {'title': unicode(link_title), 'url': link_url} |
190 |
} |
191 |
response = HttpResponse(json.dumps(response_object), mimetype='application/json') #no windows, no rdp |
192 |
|
193 |
return response
|
194 |
|
195 |
FEEDBACK_CONTACTS = getattr(settings, "FEEDBACK_CONTACTS", []) |
196 |
FEEDBACK_EMAIL_FROM = settings.FEEDBACK_EMAIL_FROM |
197 |
|
198 |
def feedback_submit(request): |
199 |
|
200 |
if not request.method == "POST": |
201 |
raise Http404
|
202 |
|
203 |
message = request.POST.get("feedback-msg")
|
204 |
data = request.POST.get("feedback-data")
|
205 |
|
206 |
# default to True (calls from error pages)
|
207 |
allow_data_send = request.POST.get("feedback-submit-data", True) |
208 |
|
209 |
mail_subject = unicode(_("Feedback from synnefo application")) |
210 |
|
211 |
mail_context = {'message': message, 'data': data, 'allow_data_send': allow_data_send, 'request': request} |
212 |
mail_content = render_to_string("feedback_mail.txt", mail_context)
|
213 |
|
214 |
if settings.DEBUG:
|
215 |
print mail_subject, mail_content
|
216 |
|
217 |
for email in FEEDBACK_CONTACTS: |
218 |
send_async( |
219 |
frm = FEEDBACK_EMAIL_FROM, |
220 |
to = "%s <%s>" % (email[0], email[1]), |
221 |
subject = mail_subject, |
222 |
body = mail_content |
223 |
) |
224 |
|
225 |
return HttpResponse("ok"); |
226 |
|
227 |
def images(request): |
228 |
context = {} |
229 |
return template('images', context) |
230 |
|
231 |
def disks(request): |
232 |
context = {} |
233 |
return template('disks', context) |
234 |
|
235 |
def networks(request): |
236 |
context = {} |
237 |
return template('networks', context) |
238 |
|
239 |
def files(request): |
240 |
context = {} |
241 |
return template('files', context) |
242 |
|
243 |
def desktops(request): |
244 |
context = {} |
245 |
return template('desktops', context) |
246 |
|
247 |
def apps(request): |
248 |
context = {} |
249 |
return template('apps', context) |