From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <d.csapak@proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256)
 (No client certificate requested)
 by lists.proxmox.com (Postfix) with ESMTPS id 959D8619AB
 for <pve-devel@lists.proxmox.com>; Thu, 10 Feb 2022 10:33:46 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 813681AAF1
 for <pve-devel@lists.proxmox.com>; Thu, 10 Feb 2022 10:33:16 +0100 (CET)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
 [94.136.29.106])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256)
 (No client certificate requested)
 by firstgate.proxmox.com (Proxmox) with ESMTPS id 3A4971AAE4
 for <pve-devel@lists.proxmox.com>; Thu, 10 Feb 2022 10:33:14 +0100 (CET)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
 by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 078B7419B7
 for <pve-devel@lists.proxmox.com>; Thu, 10 Feb 2022 10:33:14 +0100 (CET)
From: Dominik Csapak <d.csapak@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Thu, 10 Feb 2022 10:33:12 +0100
Message-Id: <20220210093312.1532271-1-d.csapak@proxmox.com>
X-Mailer: git-send-email 2.30.2
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.158 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 KAM_SHORT               0.001 Use of a URL Shortener for very short URL
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
 T_SCC_BODY_TEXT_LINE    -0.01 -
 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See
 http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more
 information. [creativecommons.org, opensource.org, fontawesome.com, sil.org,
 wikipedia.org]
Subject: [pve-devel] [PATCH novnc] don't automatically connect to not
 running vms/cts
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Thu, 10 Feb 2022 09:33:46 -0000

this patch adds a check for the guests status, and show a start button
instead of connecting to a non-started guest

this should reduce confusion when a guest is not running, and also
reduce the number of false-positive failed console tasks

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 ...ow-start-button-on-not-running-vm-ct.patch | 197 ++++++++++++++++++
 debian/patches/series                         |   1 +
 2 files changed, 198 insertions(+)
 create mode 100644 debian/patches/0018-show-start-button-on-not-running-vm-ct.patch

diff --git a/debian/patches/0018-show-start-button-on-not-running-vm-ct.patch b/debian/patches/0018-show-start-button-on-not-running-vm-ct.patch
new file mode 100644
index 0000000..3b6fc8d
--- /dev/null
+++ b/debian/patches/0018-show-start-button-on-not-running-vm-ct.patch
@@ -0,0 +1,197 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Dominik Csapak <d.csapak@proxmox.com>
+Date: Wed, 9 Feb 2022 14:50:35 +0100
+Subject: [PATCH] show start button on not running vm/ct
+
+by querying the 'status' api first and showing a simple startbutton
+if the status is not 'running'
+
+adds a play icon from fontawesome, since novnc had none itself
+
+css style is mostly copied from novnc "connect dialog", only the
+colors were adapted
+
+Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
+---
+ LICENSE.txt         | 13 ++++++++++
+ app/images/play.svg |  1 +
+ app/pve.js          | 34 ++++++++++++++++++++++++--
+ app/styles/pve.css  | 59 +++++++++++++++++++++++++++++++++++++++++++++
+ vnc.html            |  9 +++++++
+ 5 files changed, 114 insertions(+), 2 deletions(-)
+ create mode 100644 app/images/play.svg
+
+diff --git a/LICENSE.txt b/LICENSE.txt
+index ee81d20..de1bec2 100644
+--- a/LICENSE.txt
++++ b/LICENSE.txt
+@@ -60,3 +60,16 @@ Or alternatively the license texts may be found here:
+     http://scripts.sil.org/OFL
+     http://en.wikipedia.org/wiki/BSD_licenses
+     https://opensource.org/licenses/MIT
++
++Fontawesome Icon:
++
++app/images/play.svg
++(added fill color)
++
++Fonticons, Inc. (https://fontawesome.com)
++
++CC BY 4.0 License (https://creativecommons.org/licenses/by/4.0/)
++
++The Font Awesome Free download is licensed under a Creative Commons
++Attribution 4.0 International License and applies to all icons packaged
++as SVG and JS file types.
+diff --git a/app/images/play.svg b/app/images/play.svg
+new file mode 100644
+index 0000000..3cda723
+--- /dev/null
++++ b/app/images/play.svg
+@@ -0,0 +1 @@
++<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512" fill="#FFFFFF"><!--! Font Awesome Free 6.0.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2022 Fonticons, Inc. --><path d="M361 215C375.3 223.8 384 239.3 384 256C384 272.7 375.3 288.2 361 296.1L73.03 472.1C58.21 482 39.66 482.4 24.52 473.9C9.377 465.4 0 449.4 0 432V80C0 62.64 9.377 46.63 24.52 38.13C39.66 29.64 58.21 29.99 73.03 39.04L361 215z"/></svg>
+diff --git a/app/pve.js b/app/pve.js
+index 042eb7c..9da23ed 100644
+--- a/app/pve.js
++++ b/app/pve.js
+@@ -311,6 +311,11 @@ PVEUI.prototype = {
+ 		.classList.add('pve_hidden');
+ 	}
+ 
++        document.getElementById("pve_start_button")
++            .addEventListener('click', function() {
++		me.pve_vm_command('start');
++	    });
++
+ 	// add command logic
+ 	var commandArray = [
+ 	    { cmd: 'start', kvm: 1, lxc: 1},
+@@ -359,8 +364,8 @@ PVEUI.prototype = {
+ 	return { width: ow, height: oh };
+     },
+ 
+-    pveStart: function(callback) {
+-	var me = this;
++    initConnection: function(callback) {
++	let me = this;
+ 	me.API2Request({
+ 	    url: me.url,
+ 	    method: 'POST',
+@@ -382,6 +387,31 @@ PVEUI.prototype = {
+ 	});
+     },
+ 
++    pveStart: function(callback) {
++	var me = this;
++	if (me.consoletype === 'kvm' || me.consoletype === 'lxc') {
++	    // check status for vms first
++	    me.API2Request({
++		url: `${me.baseUrl}/status/current`,
++		method: 'GET',
++		success: function(result) {
++		    let status = result.data.status;
++		    if (status === 'running') {
++			me.initConnection(callback);
++		    } else {
++			document.getElementById('pve_start_dlg')
++			    .classList.add("noVNC_open");
++		    }
++		},
++		failure: function(msg) {
++		    me.UI.showStatus(msg, 'error');
++		}
++	    });
++	} else {
++	    me.initConnection(callback);
++	}
++    },
++
+     updateFBSize: function(rfb, width, height) {
+ 	var me = this;
+ 	try {
+diff --git a/app/styles/pve.css b/app/styles/pve.css
+index 18126b0..f2e7484 100644
+--- a/app/styles/pve.css
++++ b/app/styles/pve.css
+@@ -44,3 +44,62 @@
+ .noVNC_button.pve_hidden {
+   display: none;
+ }
++
++/* start button */
++#pve_start_dlg {
++  transition: 0.5s ease-in-out;
++  transform: scale(0, 0);
++  visibility: hidden;
++  opacity: 0;
++}
++
++#pve_start_dlg.noVNC_open {
++  transform: scale(1, 1);
++  visibility: visible;
++  opacity: 1;
++}
++
++#pve_start_info {
++  color: white;
++  text-align: center;
++  font-size: 20px;
++  padding: 6px;
++}
++
++#pve_start_button {
++  cursor: pointer;
++  padding: 6px;
++  color: white;
++  background:#4c4c4c;;
++  border-radius: 8px;
++  text-align: center;
++  font-size: 20px;
++  box-shadow: 4px 4px 0px rgba(0, 0, 0, 0.5);
++}
++
++#pve_start_button div {
++  margin: 2px;
++  padding: 5px 30px;
++  border: 1px solid #2f2f2f;
++  border-bottom-width: 2px;
++  border-radius: 5px;
++  background:#4c4c4c;;
++
++  /* This avoids it jumping around when :active */
++  vertical-align: middle;
++}
++
++#pve_start_button div:active {
++  border-bottom-width: 1px;
++  margin-top: 3px;
++}
++
++:root:not(.noVNC_touch) #pve_start_button div:hover {
++  background: rgba(255, 255, 255, 0.2);
++}
++
++#pve_start_button img {
++  vertical-align: bottom;
++  height: 1.3em;
++  padding: 0 10px 0 0;
++}
+diff --git a/vnc.html b/vnc.html
+index d94fd99..72efa89 100644
+--- a/vnc.html
++++ b/vnc.html
+@@ -283,6 +283,15 @@
+         </div>
+     </div>
+ 
++    <div class="noVNC_center">
++        <div id="pve_start_dlg">
++            <div id="pve_start_info">VM/CT not running</div>
++            <div id="pve_start_button"><div>
++                <img alt="" src="/novnc/app/images/play.svg"> Start VM/CT
++            </div></div>
++        </div>
++    </div>
++
+     <!-- Password Dialog -->
+     <div class="noVNC_center noVNC_connect_layer">
+     <div id="noVNC_credentials_dlg" class="noVNC_panel"><form>
diff --git a/debian/patches/series b/debian/patches/series
index a520e27..085e2b4 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -15,3 +15,4 @@
 0015-create-own-class-for-hidden-buttons.patch
 0016-hide-fullscreen-button-on-isFullscreen-get-variable.patch
 0017-make-error-hideable.patch
+0018-show-start-button-on-not-running-vm-ct.patch
-- 
2.30.2