[Kimchi-devel] [PATCH] set the password for spice and VNC page.

shaohef at linux.vnet.ibm.com shaohef at linux.vnet.ibm.com
Mon Aug 4 14:48:14 UTC 2014


From: ShaoHe Feng <shaohef at linux.vnet.ibm.com>

set a cookie to store the ticket before connect a VM.
get the password from cookie and pass it to spice and VNC server.

Signed-off-by: ShaoHe Feng <shaohef at linux.vnet.ibm.com>
---
 ui/js/novnc/main.js            | 10 +++++++++-
 ui/js/src/kimchi.guest_main.js | 22 ++++++++++++++++------
 ui/pages/spice.html.tmpl       | 10 +++++++++-
 3 files changed, 34 insertions(+), 8 deletions(-)

diff --git a/ui/js/novnc/main.js b/ui/js/novnc/main.js
index 22037ec..84a813b 100644
--- a/ui/js/novnc/main.js
+++ b/ui/js/novnc/main.js
@@ -79,7 +79,15 @@ if (token) {
     WebUtil.createCookie('token', token, 1)
 }
 
-password = WebUtil.getQueryVar('password', '');
+// password = WebUtil.getQueryVar('password', '');
+var cookieRe = new RegExp(';?\\\s*(ticketVM)=(\s*[^;]*);?', 'g');
+var match = cookieRe.exec(document.cookie);
+var password = match ? decodeURIComponent(match[2]) : '';
+if (match) {
+    var utcString = new Date().toUTCString();
+    document.cookie = 'ticketVM' + '=; expires=' + utcString;
+}
+
 path = WebUtil.getQueryVar('path', 'websockify');
 
 if ((!host) || (!port)) {
diff --git a/ui/js/src/kimchi.guest_main.js b/ui/js/src/kimchi.guest_main.js
index ff6f2e1..1c1428f 100644
--- a/ui/js/src/kimchi.guest_main.js
+++ b/ui/js/src/kimchi.guest_main.js
@@ -150,12 +150,22 @@ kimchi.vmedit = function(event) {
 kimchi.openVmConsole = function(event) {
     var vm=$(this).closest('li[name=guest]');
     var vmObject=vm.data();
-    if (vmObject.graphics['type'] == 'vnc') {
-        kimchi.vncToVM(vm.attr('id'));
-    }
-    else if (vmObject.graphics['type'] == 'spice') {
-        kimchi.spiceToVM(vm.attr('id'));
-    }
+    kimchi.retrieveVM(vm.attr('id'), function(result) {
+            if (result.ticket.expire  && result.ticket.expire < 0) {
+                kimchi.message.error('please reset your password!');
+                return;
+            }
+            result.ticket.passwd != null && kimchi.cookie.set("ticketVM", result.ticket.passwd, 100);
+            if (vmObject.graphics['type'] == 'vnc') {
+                kimchi.vncToVM(vm.attr('id'));
+            }
+            else if (vmObject.graphics['type'] == 'spice') {
+                kimchi.spiceToVM(vm.attr('id'));
+            }
+        }, function(err) {
+            kimchi.message.error(err.responseJSON.reason);
+        }
+    );
 
 };
 
diff --git a/ui/pages/spice.html.tmpl b/ui/pages/spice.html.tmpl
index 213d216..cb7c331 100644
--- a/ui/pages/spice.html.tmpl
+++ b/ui/pages/spice.html.tmpl
@@ -64,6 +64,14 @@
             host = getParameter("listen");
             port = getParameter("port");
             token = getParameter("token");
+            var cookieRe = new RegExp(';?\\\s*(ticketVM)=(\s*[^;]*);?', 'g');
+            var match = cookieRe.exec(document.cookie);
+            password = match ? decodeURIComponent(match[2]) : '';
+            if (match) {
+                var utcString = new Date().toUTCString();
+                document.cookie = 'ticketVM' + '=; expires=' + utcString;
+            }
+
             document.getElementById("host").value = host;
             document.getElementById("port").value = port;
             if ((!host) || (!port)) {
@@ -82,7 +90,7 @@
                     screen_id : "spice-screen",
                     dump_id : "debug-div",
                     message_id : "message-div",
-                    password : "",
+                    password : password,
                     onerror : spice_error
                 });
             } catch (e) {
-- 
1.9.3




More information about the Kimchi-devel mailing list