Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ASM
edulab-frontend
Commits
a5c7b5f8
Commit
a5c7b5f8
authored
Jul 05, 2017
by
Andreas Åkre Solberg
Browse files
Show RDP link for windows VMs
parent
5870a768
Pipeline
#2958
passed with stages
in 1 minute
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
lib/EduLab.js
View file @
a5c7b5f8
...
...
@@ -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\n
prompt 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
);
...
...
lib/models/Lab.js
View file @
a5c7b5f8
...
...
@@ -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
;
...
...
lib/models/Machine.js
View file @
a5c7b5f8
...
...
@@ -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
;
}
...
...
views/machines.mustache
View file @
a5c7b5f8
...
...
@@ -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
}}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment