Revision d0e3f226 ui/views.py
b/ui/views.py | ||
---|---|---|
135 | 135 |
server_id = request.GET.get('srv', 0) |
136 | 136 |
host_os = request.GET.get('host_os','Linux').lower() |
137 | 137 |
username = request.GET.get('username', None) |
138 |
domain = request.GET.get("domain", "snf-%d" % int(server_id)) |
|
138 | 139 |
|
140 |
# guess host os |
|
139 | 141 |
if host_os != "windows": |
140 | 142 |
host_os = 'linux' |
141 | 143 |
|
144 |
# guess username |
|
145 |
if not username: |
|
146 |
username = "root" |
|
147 |
|
|
148 |
if metadata_os.lower() in ['ubuntu', 'kubuntu', 'fedora']: |
|
149 |
username = "user" |
|
150 |
|
|
151 |
if metadata_os.lower() == "windows": |
|
152 |
username = "Administrator" |
|
153 |
|
|
154 |
# operating system provides ssh access |
|
155 |
ssh = False |
|
142 | 156 |
if operating_system != "windows": |
143 | 157 |
operating_system = "linux" |
158 |
ssh = True |
|
144 | 159 |
|
145 | 160 |
# rdp param is set, the user requested rdp file |
146 |
if operating_system == 'windows' and request.GET.get("rdp", False): #check if we are on windows |
|
147 |
rdp_file = os.path.join(os.path.dirname(__file__), "static/") + 'synnefo-windows.rdp' |
|
148 |
connect_data = open(rdp_file, 'r').read() |
|
149 |
connect_data = connect_data + 'full address:s:' + ip_address + '\n' |
|
150 |
response = HttpResponse(connect_data, mimetype='application/x-rdp') |
|
161 |
# check if we are on windows |
|
162 |
if operating_system == 'windows' and request.GET.get("rdp", False): |
|
163 |
|
|
164 |
# UI sent domain info (from vm metadata) use this |
|
165 |
# otherwise use our default snf-<vm_id> domain |
|
166 |
rdp_context = { |
|
167 |
'username': username, |
|
168 |
'domain': domain, |
|
169 |
'ip_address': ip_address |
|
170 |
} |
|
171 |
|
|
172 |
rdp_file_data = render_to_string("synnefo-windows.rdp", rdp_context) |
|
173 |
response = HttpResponse(rdp_file_data, mimetype='application/x-rdp') |
|
151 | 174 |
|
152 | 175 |
# proper filename, use server id and ip address |
153 | 176 |
filename = "%d-%s.rdp" % (int(server_id), ip_address) |
154 | 177 |
response['Content-Disposition'] = 'attachment; filename=%s' % filename |
155 | 178 |
else: |
156 |
# no rdp requested return json object with info on how to connect |
|
157 |
ssh = False |
|
158 |
if (operating_system != "windows"): |
|
159 |
ssh = True |
|
160 |
|
|
161 | 179 |
link_title = _("Remote desktop to %s") % ip_address |
162 |
link_url = "%s?ip_address=%s&os=%s&rdp=1&srv=%d" % (reverse("machines-connect"), ip_address, operating_system, |
|
163 |
int(server_id)) |
|
164 |
|
|
165 |
user = username |
|
166 |
if not user: |
|
167 |
user = "root" |
|
168 |
if metadata_os.lower() in ['ubuntu', 'kubuntu', 'fedora']: |
|
169 |
user = "user" |
|
180 |
link_url = "%s?ip_address=%s&os=%s&rdp=1&srv=%d&username=%s&domain=%s" % ( |
|
181 |
reverse("machines-connect"), ip_address, operating_system,int(server_id), username, domain) |
|
170 | 182 |
|
171 | 183 |
if (operating_system != "windows"): |
172 |
link_title = "ssh %s@%s" % (user, ip_address) |
|
184 |
link_title = "ssh %s@%s" % (username, ip_address)
|
|
173 | 185 |
link_url = None |
174 | 186 |
|
175 | 187 |
if host_os == "windows": |
176 |
link_title = "%s@%s" % (user, ip_address) |
|
188 |
link_title = "%s@%s" % (username, ip_address)
|
|
177 | 189 |
|
178 | 190 |
# try to find a specific message |
179 | 191 |
try: |
Also available in: Unified diff