[pve-devel] r5151 - in qemu-server/pve2: . PVE PVE/API2/Qemu

svn-commits at proxmox.com svn-commits at proxmox.com
Wed Sep 15 08:04:37 CEST 2010


Author: dietmar
Date: 2010-09-15 06:04:36 +0000 (Wed, 15 Sep 2010)
New Revision: 5151

Modified:
   qemu-server/pve2/PVE/API2/Qemu/VNC.pm
   qemu-server/pve2/PVE/QemuServer.pm
   qemu-server/pve2/nqm
Log:


Modified: qemu-server/pve2/PVE/API2/Qemu/VNC.pm
===================================================================
--- qemu-server/pve2/PVE/API2/Qemu/VNC.pm	2010-09-14 10:46:54 UTC (rev 5150)
+++ qemu-server/pve2/PVE/API2/Qemu/VNC.pm	2010-09-15 06:04:36 UTC (rev 5151)
@@ -17,5 +17,45 @@
 
 use base qw(PVE::RESTHandler);
 
+__PACKAGE__->register_method ({
+    name => 'vncproxy', 
+    path => '',  
+    method => 'POST',
+    description => "Create VNC proxy connections.",
+    parameters => {
+    	additionalProperties => 0,
+	properties => {
+	    node => get_standard_option('pve-node'),
+	    vmid => get_standard_option('pve-vmid'),
+	},
+    },
+    returns => { 
+    	additionalProperties => 0,
+	properties => {
+	    port => { type => 'integer' },
+	    ticket => { type => 'string' },
+	},
+    },
+    code => sub {
+	my ($param) = @_;
 
+	my $rpcenv = PVE::RPCEnvironment::get();
+
+	my $user = $rpcenv->get_user();
+
+	my $vmid = $param->{vmid};
+	my $node = $param->{node};
+
+	# generate ticket, olny first 8 character used by vnc
+	my $ticket = Digest::SHA1::sha1_base64 ($userid, rand(), time());
+
+	my $port = PVE::QemuServer::next_vnc_port();
+
+	print "TEST VNCPROXY\n";
+
+
+	return { port = $port, ticket => $ticket };
+
+    }});
+
 1;

Modified: qemu-server/pve2/PVE/QemuServer.pm
===================================================================
--- qemu-server/pve2/PVE/QemuServer.pm	2010-09-14 10:46:54 UTC (rev 5150)
+++ qemu-server/pve2/PVE/QemuServer.pm	2010-09-15 06:04:36 UTC (rev 5151)
@@ -462,6 +462,13 @@
     $confdesc->{"virtio$i"} = $virtiodesc;
 }
 
+PVE::JSONSchema::register_standard_option('pve-vncticket', { 
+    description => "Secret VNC ticket.",
+    type => 'string',
+    minLength => 8, # just to improve security
+    pattern => '[A-Za-z0-9\+\/\=]+', # base64 characters
+});
+
 my $kvm_api_version = 0;
 
 sub kvm_version {
@@ -2033,6 +2040,25 @@
     die "unable to find free migration port";
 }
 
+sub next_vnc_port {
+
+    for (my $p = 5900; $p < 6000; $p++) {
+
+	my $sock = IO::Socket::INET->new (Listen => 5,
+					  LocalAddr => 'localhost',
+					  LocalPort => $p,
+					  ReuseAddr => 1,
+					  Proto     => 0);
+
+	if ($sock) {
+	    close ($sock);
+	    return $p;
+	}
+    }
+
+    die "unable to find free vnc port";
+};
+
 sub activate_volumes {
     my ($storecfg, $conf)  = @_;
 

Modified: qemu-server/pve2/nqm
===================================================================
--- qemu-server/pve2/nqm	2010-09-14 10:46:54 UTC (rev 5150)
+++ qemu-server/pve2/nqm	2010-09-15 06:04:36 UTC (rev 5151)
@@ -157,13 +157,7 @@
     	additionalProperties => 0,
 	properties => {
 	    vmid => get_standard_option('pve-vmid'),
-	    ticket => { 
-		description => "VNC auth ticket.",
-		type => 'string',
-		optional => 1,
-		minLength => 8, # just to improve security
-		pattern => '[A-Za-z0-9\+\/\=]+', # base64 characters
-	    },
+	    ticket => get_standard_option('pve-vncticket', { optional => 1 }), 
 	},
     },
     returns => { type => 'null'},




More information about the pve-devel mailing list