Commit a5c7b5f8 authored by Andreas Åkre Solberg's avatar Andreas Åkre Solberg
Browse files

Show RDP link for windows VMs

parent 5870a768
Pipeline #2958 passed with stages
in 1 minute
......@@ -10,6 +10,13 @@ var Machine = require('./models/Machine').Machine;
const APIBASE = 'https://edulab.dataporten-api.no';
function ValidateIPaddress(ipaddress) {
if (/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(ipaddress)) {
return (true)
}
return (false)
}
class EduLab {
constructor(opts) {
this.opts = opts || {};
......@@ -19,6 +26,7 @@ class EduLab {
this.router.get('/debug', (req, res) => this.debug(req, res) );
this.router.get('/create-lab', (req, res) => this.createLab(req, res) );
this.router.get('/lab/:labid', (req, res) => this.labview(req, res) );
this.router.get('/rdp', (req, res) => this.rdp(req, res) );
this.router.get('/api/configuration', (req, res) => this.backendConfiguration(req, res));
this.router.post('/api/create-lab', (req, res) => this.APIcreateLab(req, res));
this.router.post('/api/create-machine', (req, res) => this.APIcreateMachine(req, res));
......@@ -71,6 +79,28 @@ class EduLab {
return this.getCustomAPIrequest(req, opts);
}
rdp(req, res) {
try {
if (!ValidateIPaddress(req.query.address)) {
throw new Error("Invalid IP Address");
}
res.setHeader('Content-Type', 'application/x-rdp');
// res.setHeader('Content-Type', 'text/plain');
res.setHeader('Content-Disposition', 'attachment; filename=' + req.query.address + '.rdp');
res.end("full address:s:" + req.query.address + ":3389\r\nprompt for credentials:i:1");
} catch(err) {
console.error("Error debug page", err);
console.error(err)
res.render('error', err);
}
}
APIcreateLab(req, res) {
console.log("Request", req.body);
......
......@@ -25,6 +25,7 @@ class Lab {
view.edulab_hwprofile_ids_list = this.props.edulab_hwprofile_ids.join(' ');
view.edulab_image_ids_list = this.props.edulab_image_ids.join(' ');
// console.log("Lab view");
// console.log(view);
return view;
......
......@@ -45,6 +45,7 @@ class Machine {
view.icon = 'https://api.dataporten.no/userinfo/v1/user/media/' + this.props.extended_properties.dataporten_profilephoto;
}
view.showRdp = (this.props.extended_properties.osType === 'windows');
return view;
}
......
......@@ -40,6 +40,7 @@
<th>VM Status</th>
<th>Instanstype</th>
<th>RDP</th>
<th>Kjørestatus</th>
<th>Options</th>
</tr>
......@@ -60,12 +61,26 @@
<td>{{ provisioning_state }}</td>
<td><a target="_blank" href="https://docs.microsoft.com/nb-no/azure/virtual-machines/windows/sizes-general#av2-series">{{ vm_size }}</a></td>
<td >
{{#showRdp}}
{{#may.stop}}
<a href="/rdp?address={{ publicIp }}" name="button" class="btn btn-xs btn-default">
<i style="color: #484" class="glyphicon glyphicon-modal-window"></i> RDP
</button>
{{/may.stop}}
{{/showRdp}}
{{^showRdp}}
NA
{{/showRdp}}
</td>
<td rowspan="2">
{{#may.stop}}<i style="color: #484" class="glyphicon glyphicon-play"></i> {{/may.stop}}
{{#may.start}}<i style="color: red" class="glyphicon glyphicon-pause"></i> {{/may.start}}
{{ display_status }}</td>
{{ display_status }}
</td>
<td rowspan="2">
{{#may.stop}}<button type="button" name="button" data-vmid="{{ name }}" class="vmstop btn btn-xs btn-default"><i class="glyphicon glyphicon-pause"></i> Stopp</button>{{/may.stop}}
{{#may.start}}<button type="button" name="button" data-vmid="{{ name }}" class="vmstart btn btn-xs btn-primary"><i class="glyphicon glyphicon-play"></i> Start</button>{{/may.start}}
......@@ -75,13 +90,13 @@
</td>
</tr>
<tr>
<td colspan="3">
<td colspan="4">
<tt style="padding-left: 2em; font-size: 80%">
{{#fqdn}}
{{.}}
{{/fqdn}}
{{^fqdn}}
{{ name }} -
{{ name }} -
{{ publicIp }}
{{/fqdn}}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment