Skip to content

Instantly share code, notes, and snippets.

@joelrebel
Last active July 20, 2022 13:49
Show Gist options
  • Save joelrebel/b04940ff8e424ff360fba7000b0df1e5 to your computer and use it in GitHub Desktop.
Save joelrebel/b04940ff8e424ff360fba7000b0df1e5 to your computer and use it in GitHub Desktop.
Proxy secure websocket connections (wss://)

Generate self signed certs openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /tmp/private/nginx-selfsigned.key -out /tmp/nginx-selfsigned.crt

Import self signed certs into browser (firefox)

# add the local nginx proxy as an exception,
settings -> view certificates 
   -> Servers tab -> Add exception -> location https//localhost:9000 -> Get certificates -> confirm security exception
   -> Authorities tab -> Edit trust on the added certificate -> select "This certificate can identify websites" and "This certificate can identify mail users" -> ok

run websockets proxy with certs nginx -c nginx.conf

error_log /tmp/nginx.log;
events {
    debug_connection <BMC IP>;
    debug_connection 127.0.0.1;
}

http {
  server {
   listen 127.0.0.1:9000 ssl;
   ssl_certificate /tmp/nginx-selfsigned.crt;
   ssl_certificate_key /tmp/private/nginx-selfsigned.key;

   location / {
     proxy_pass https://<BMC IP>;
     proxy_pass_request_headers on;

     # the following headers are required for this proxy to work
     #  http://nginx.org/en/docs/http/websocket.html
     proxy_http_version 1.1;
     proxy_read_timeout 86400;
     proxy_set_header Upgrade $http_upgrade;
     proxy_set_header Connection "Upgrade";
   }
 }
}

webui-vue websocket endpoint changes

diff --git a/src/store/plugins/WebSocketPlugin.js b/src/store/plugins/WebSocketPlugin.js                                                                                                                  
index cbdc932..95351a4 100644                                                     
--- a/src/store/plugins/WebSocketPlugin.js                                                           
+++ b/src/store/plugins/WebSocketPlugin.js                                                           
@@ -22,7 +22,7 @@ const WebSocketPlugin = (store) => {                                                
       process.env.VUE_APP_SUBSCRIBE_SOCKET_DISABLED === 'true' ? true : false;                       
     if (socketDisabled) return;                                                                     
     const token = store.getters['authentication/token'];                                             
-    ws = new WebSocket(`wss://${window.location.host}/subscribe`, [token]);                         
+    ws = new WebSocket(`wss://localhost:9000/subscribe`, [token]);                                   
     ws.onopen = () => {                          
       ws.send(JSON.stringify(data));                                             
     };                                           
diff --git a/src/views/Operations/Kvm/KvmConsole.vue b/src/views/Operations/Kvm/KvmConsole.vue                                                                                                              
index c028a9f..479b6d4 100644                                                     
--- a/src/views/Operations/Kvm/KvmConsole.vue     
+++ b/src/views/Operations/Kvm/KvmConsole.vue     
@@ -106,11 +106,9 @@ export default {                                             
     },                                                                           
     openTerminal() {                             
       const token = this.$store.getters['authentication/token'];                                                                                                                                          
-      this.rfb = new RFB(                                                        
-        this.$refs.panel,                                                                           
-        `wss://${window.location.host}/kvm/0`,                                                      
-        { wsProtocols: [token] }                                                 
-      );                                         
+      this.rfb = new RFB(this.$refs.panel, `wss://localhost:9000/kvm/0`, {                          
+        wsProtocols: [token],                    
+      });                                                                                           
                                                  
       this.rfb.scaleViewport = true;             
       this.rfb.clipViewport = true;               
@@ -130,6 +128,7 @@ export default {               
       this.rfb.addEventListener('disconnect', () => {                                                
         this.isConnected = false;                 
         that.status = Disconnected;               
+        console.log(that.status);                 
       });                                         
     },                                            
     setWidthToolbar() {                           
diff --git a/src/views/Operations/SerialOverLan/SerialOverLanConsole.vue b/src/views/Operations/SerialOverLan/SerialOverLanConsole.vue
index 694083f..abbe870 100644                      
--- a/src/views/Operations/SerialOverLan/SerialOverLanConsole.vue                                     
+++ b/src/views/Operations/SerialOverLan/SerialOverLanConsole.vue                                     
@@ -91,9 +91,7 @@ export default {                 
     openTerminal() {                              
       const token = this.$store.getters['authentication/token'];                                     
                                                   
-      this.ws = new WebSocket(`wss://${window.location.host}/console0`, [                            
-        token,                                    
-      ]);                                         
+      this.ws = new WebSocket(`wss://localhost:9000/console0`, [token]);                             
                                                   
       // Refer https://github.com/xtermjs/xterm.js/ for xterm implementation and addons.
                                                   
diff --git a/src/views/Operations/VirtualMedia/VirtualMedia.vue b/src/views/Operations/VirtualMedia/VirtualMedia.vue
index 8a3d5ad..42a6b6d 100644                      
--- a/src/views/Operations/VirtualMedia/VirtualMedia.vue                                              
+++ b/src/views/Operations/VirtualMedia/VirtualMedia.vue                                              
@@ -137,7 +137,7 @@ export default {               
     startVM(device) {                             
       const token = this.$store.getters['authentication/token'];                                     
       device.nbd = new NbdServer(                 
-        `wss://${window.location.host}${device.websocket}`,                                          
+        `wss://localhost:9000${device.websocket}`,                                                   
         device.file,                              
         device.id,                                
         token               
@sivaprabug
Copy link

How to run locally?

BMC live IP is 172.31.2.250

Create file like

webui-vue**.env.development.local**

Add below url

BASE_URL="https://172.31.2.250"

then
npm run serve

Not able to connect BMC have any idea?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment