VNC proxy working in the worker!!
Confirmed multi client access too Streamlit button added
This commit is contained in:
@@ -2,6 +2,37 @@ import json
|
||||
import streamlit as st
|
||||
from streamlit_server.utils.helpers import format_timestamp
|
||||
|
||||
import jwt
|
||||
import base64
|
||||
import json
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
def generate_vnc_url(virtual_machine_id: str, secret_key: str) -> str:
|
||||
"""
|
||||
Generates a signed and base64-encoded VNC token URL for a given VM ID.
|
||||
"""
|
||||
user_payload = {
|
||||
"sub": "user_id_1234",
|
||||
"name": "Console User",
|
||||
"role": "admin",
|
||||
"exp": datetime.utcnow() + timedelta(hours=3000),
|
||||
"iat": datetime.utcnow()
|
||||
}
|
||||
|
||||
user_token = jwt.encode(user_payload, secret_key, algorithm="HS256")
|
||||
if isinstance(user_token, bytes):
|
||||
user_token = user_token.decode("utf-8")
|
||||
|
||||
outer_payload = {
|
||||
"virtual_machine_id": virtual_machine_id,
|
||||
"user_token": user_token
|
||||
}
|
||||
|
||||
token_bytes = json.dumps(outer_payload).encode("utf-8")
|
||||
token_b64 = base64.urlsafe_b64encode(token_bytes).decode("utf-8").rstrip("=")
|
||||
|
||||
return f"http://127.0.0.1:8080/vnc.html?autoconnect=true&host=127.0.0.1&port=6002&path=vnc?token={token_b64}"
|
||||
|
||||
|
||||
def render_list():
|
||||
"""
|
||||
@@ -212,6 +243,13 @@ def render_list():
|
||||
st.session_state[confirm_key] = False
|
||||
|
||||
with st.popover("Actions", use_container_width=True):
|
||||
if VirtualMachine['status'] == "running":
|
||||
vnc_url = generate_vnc_url(VirtualMachine['id'], "your-very-secret-key") # replace with secure source
|
||||
st.page_link(vnc_url,label="VNC")
|
||||
# if st.button("Open Console", key=f"console_{VirtualMachine['id']}", use_container_width=True):
|
||||
# js = f"window.open('{vnc_url}', '_blank')"
|
||||
# st.markdown(f"<script>{js}</script>", unsafe_allow_html=True)
|
||||
|
||||
# View Details Button
|
||||
if st.button("View Details", key=f"popover_view_{VirtualMachine['id']}", use_container_width=True):
|
||||
st.session_state.selected_resource = VirtualMachine
|
||||
|
||||
Reference in New Issue
Block a user