Browse Source

Added experimental usb mass storage switch

TC 2 weeks ago
parent
commit
60ac00d058
6 changed files with 88 additions and 0 deletions
  1. 16 0
      remdeskd/api.go
  2. 3 0
      remdeskd/mod/remdesaux/handlers.go
  3. 3 0
      remdeskd/usbkvm.go
  4. 8 0
      remdeskd/www/index.html
  5. 11 0
      remdeskd/www/main.css
  6. 47 0
      remdeskd/www/ui.js

+ 16 - 0
remdeskd/api.go

@@ -20,3 +20,19 @@ func registerLocalAuxRoutes() {
 	http.HandleFunc("/aux/releasereset", auxMCU.HandleReleaseResetButton)
 	http.HandleFunc("/aux/getuuid", auxMCU.HandleGetUUID)
 }
+
+// Dummy Aux APIs for setups that do not have an aux MCU
+func registerDummyLocalAuxRoutes() {
+	dummyHandler := func(w http.ResponseWriter, r *http.Request) {
+		w.WriteHeader(http.StatusNotImplemented)
+		w.Write([]byte("Not implemented"))
+	}
+
+	http.HandleFunc("/aux/switchusbkvm", dummyHandler)
+	http.HandleFunc("/aux/switchusbremote", dummyHandler)
+	http.HandleFunc("/aux/presspower", dummyHandler)
+	http.HandleFunc("/aux/releasepower", dummyHandler)
+	http.HandleFunc("/aux/pressreset", dummyHandler)
+	http.HandleFunc("/aux/releasereset", dummyHandler)
+	http.HandleFunc("/aux/getuuid", dummyHandler)
+}

+ 3 - 0
remdeskd/mod/remdesaux/handlers.go

@@ -2,6 +2,7 @@ package remdesaux
 
 import (
 	"encoding/json"
+	"log"
 	"net/http"
 )
 
@@ -11,6 +12,7 @@ func (c *AuxMcu) HandleSwitchUSBToKVM(w http.ResponseWriter, r *http.Request) {
 		http.Error(w, err.Error(), http.StatusInternalServerError)
 		return
 	}
+	log.Println("Switched USB mass storage to KVM side")
 	w.WriteHeader(http.StatusOK)
 }
 
@@ -20,6 +22,7 @@ func (c *AuxMcu) HandleSwitchUSBToRemote(w http.ResponseWriter, r *http.Request)
 		http.Error(w, err.Error(), http.StatusInternalServerError)
 		return
 	}
+	log.Println("Switched USB mass storage to remote side")
 	w.WriteHeader(http.StatusOK)
 }
 

+ 3 - 0
remdeskd/usbkvm.go

@@ -113,6 +113,9 @@ func startUsbKvmMode(config *UsbKvmConfig) error {
 	uuid, err := auxMCU.GetUUID()
 	if err != nil {
 		log.Println("Get UUID failed:", err, " - Auxiliary MCU may not be connected.")
+
+		//Register dummy AUX routes if failed to get UUID
+		registerDummyLocalAuxRoutes()
 	} else {
 		log.Println("Auxiliary MCU found with UUID:", uuid)
 

+ 8 - 0
remdeskd/www/index.html

@@ -5,6 +5,7 @@
     <meta name="viewport" content="width=device-width, initial-scale=1.0">
     <meta name="description" content="dezuKVM Management Interface">
     <meta name="author" content="imuslab">
+    <meta name="csrf-token" content="">
     <title>Connected | dezuKVM</title>
     
     <!-- OpenGraph Metadata -->
@@ -18,6 +19,13 @@
 </head>
 <body>
     <img id="remoteCapture" src="/stream" oncontextmenu="return false;"></img>
+    <div id="menu">
+        <button id="btnFullScreen" onclick="toggleFullScreen()">Fullscreen</button>
+        <button id="btnCtrlAltDel" onclick="sendCtrlAltDel()">Ctrl+Alt+Del</button>
+        <button id="btnFullScreen" onclick="switchMassStorageToKvm()">Switch Storage to KVM</button>
+        <button id="btnFullScreen" onclick="switchMassStorageToRemote()">Switch Storage to Remote</button>
+    </div>
+    <script src="ui.js"></script>
     <script src="kvmevt.js"></script>
 </body>
 </html>

+ 11 - 0
remdeskd/www/main.css

@@ -19,4 +19,15 @@ body {
     display: block;
     margin: auto;
     object-fit: contain;
+}
+
+#menu {
+    position: fixed;
+    top: 0px;
+    left: 50%;
+    transform: translateX(-50%);
+    padding: 10px;
+    display: flex;
+    gap: 10px;
+    z-index: 1000;
 }

+ 47 - 0
remdeskd/www/ui.js

@@ -0,0 +1,47 @@
+/*
+    ui.js
+    
+*/
+
+function cjax(object){
+    let csrf_token = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
+    $.ajax({
+        url: object.url,
+        type: object.type || 'POST',
+        data: object.data || {},
+        headers: {
+            'X-CSRF-Token': csrf_token
+        },
+        success: object.success,
+        error: object.error
+    });
+}
+
+// Add cjax as a jQuery method
+$.cjax = cjax;
+
+function switchMassStorageToRemote(){
+    $.cjax({
+        url: '/aux/switchusbremote',
+        type: 'GET',
+        success: function(response) {
+            //alert('Mass Storage switched to Remote successfully.');
+        },
+        error: function(xhr, status, error) {
+            alert('Error switching Mass Storage to Remote: ' + error);
+        }
+    });
+}
+
+function switchMassStorageToKvm(){
+    $.cjax({
+        url: '/aux/switchusbkvm',
+        type: 'GET',
+        success: function(response) {
+            //alert('Mass Storage switched to KVM successfully.');
+        },
+        error: function(xhr, status, error) {
+            alert('Error switching Mass Storage to KVM: ' + error);
+        }
+    });
+}