Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2014
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.53 KB | None | 0 0
  1. __PACKAGE__->register_method({
  2.     name => 'vncwebsocket',
  3.     path => '{vmid}/vncwebsocket',
  4.     method => 'GET',
  5.     permissions => {
  6.     description => "You also need to pass a valid ticket (vncticket).",
  7.     check => ['perm', '/vms/{vmid}', [ 'VM.Console' ]],
  8.     },
  9.     description => "Opens a weksocket for VNC traffic.",
  10.     parameters => {
  11.         additionalProperties => 0,
  12.     properties => {
  13.         node => get_standard_option('pve-node'),
  14.         vmid => get_standard_option('pve-vmid'),
  15.         vncticket => {
  16.         description => "Ticket from previous call to vncproxy.",
  17.         type => 'string',
  18.         maxLength => 512,
  19.         },
  20.         port => {
  21.         description => "Port number returned by previous vncproxy call.",
  22.         type => 'integer',
  23.         minimum => 5900,
  24.         maximum => 5999,
  25.         },
  26.     },
  27.     },
  28.     returns => {
  29.     type => "object",
  30.     properties => {
  31.         port => { type => 'string' },
  32.     },
  33.     },
  34.     code => sub {
  35.     my ($param) = @_;
  36.  
  37.     my $rpcenv = PVE::RPCEnvironment::get();
  38.  
  39.     my $authuser = $rpcenv->get_user();
  40.  
  41.     my $vmid = $param->{vmid};
  42.     my $node = $param->{node};
  43.  
  44.     my $authpath = "/vms/$vmid";
  45.  
  46.     PVE::AccessControl::verify_vnc_ticket($param->{vncticket}, $authuser, $authpath);
  47.  
  48.     my $conf = PVE::QemuServer::load_config($vmid, $node); # VM exists ?
  49.  
  50.     # Note: VNC ports are acessible from outside, so we do not gain any
  51.     # security if we verify that $param->{port} belongs to VM $vmid. This
  52.     # check is done by verifying the VNC ticket (inside VNC protocol).
  53.  
  54.     my $port = $param->{port};
  55.    
  56.     return { port => $port };
  57.     }});
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement