Skip to content

Instantly share code, notes, and snippets.

@apocas
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apocas/c5e993163ba7b6b8aaa0 to your computer and use it in GitHub Desktop.
Save apocas/c5e993163ba7b6b8aaa0 to your computer and use it in GitHub Desktop.
Opennebula VNC token
//fetching/scraping'ish the VNC token for a VM
request.post({
'url': host + '/login',
'auth': {
'user': username,
'pass': password,
'sendImmediately': true
}
}, function(err, res, body) {
cookie = res.headers['set-cookie'][0].split(';')[0];
request.get({
'url': host + '/',
headers: {
'Cookie': cookie
}
}, function(err, res, body) {
cookie = cookie + '; ' + res.headers['set-cookie'][0].split(';')[0];
var aux = body.indexOf('csrftoken') + 11;
csrftoken = body.slice(aux, aux + 32);
request.post({
'url': host + '/vm/' + vmid + '/startvnc',
headers: {
'Cookie': cookie
},
formData: {
'csrftoken': csrftoken
}
}, function(err, res, body) {
if (err) {
return console.error(err);
}
//console.log(res.statusCode);
console.log(JSON.parse(body).token);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment