Hey Folks,
I'm needing a bit of help here and if someone can point me in the right direction, it would be greatly appreciated.
What I'm trying to do is create a bash script which has proxmox credentials and the VMID and from those, print a URL where by when I click it, it will open up a browser and be able to access the VNC console immediately (via a authentication ticket).
(I'm posting some dummy credential data)
This is what I have so far:
I thought that this would work, however, it is resulting in "Error 401: No ticket"
Here is the resulting URL:
https://192.168.2.51:8006/?console=...Z0yapSElgVzbKSEUFuMPZvL0qpjdCwjmAnhETKg7H3g==
Would anybody be able to point me in the right direction? It feels so close.
Thanks!
I'm needing a bit of help here and if someone can point me in the right direction, it would be greatly appreciated.
What I'm trying to do is create a bash script which has proxmox credentials and the VMID and from those, print a URL where by when I click it, it will open up a browser and be able to access the VNC console immediately (via a authentication ticket).
(I'm posting some dummy credential data)
This is what I have so far:
Bash:
#!/bin/bash
# Proxmox API settings
PROXMOX_HOST="192.168.103.21:8006"
API_USER="root@pam"
API_PASSWORD="abcde12345"
VM_ID=100
# Step 1: Log in and get the ticket and CSRFPreventionToken
response=$(curl -k -s "https://${PROXMOX_HOST}/api2/json/access/ticket" \
-d "username=${API_USER}&password=${API_PASSWORD}" \
-H "Content-Type: application/x-www-form-urlencoded")
TICKET=$(echo $response | jq -r '.data.ticket')
CSRF_TOKEN=$(echo $response | jq -r '.data.CSRFPreventionToken')
COOKIE="PVEAuthCookie=${TICKET}"
# Step 2: Get the VM's current node and VM name
node_response=$(curl -k -s "https://${PROXMOX_HOST}/api2/json/cluster/resources?type=vm" \
--cookie "PVEAuthCookie=$TICKET")
NODE=$(echo $node_response | jq -r --arg VM_ID "$VM_ID" '.data[] | select(.vmid == ($VM_ID|tonumber)) | .node')
VMNAME=$(echo $node_response | jq -r --arg VM_ID "$VM_ID" '.data[] | select(.vmid == ($VM_ID|tonumber)) | .name')
# Step 3: Create a VNC ticket specifically for VNC access
vnc_ticket_response=$(curl -k -s "https://${PROXMOX_HOST}/api2/json/nodes/$NODE/qemu/$VM_ID/vncproxy" \
--cookie "PVEAuthCookie=$TICKET" \
-H "CSRFPreventionToken: $CSRF_TOKEN" -d '')
VNC_TICKET=$(echo $vnc_ticket_response | jq -r '.data.ticket')
# Step 4: Generate the VNC URL with the ticket
VNC_URL="https://${PROXMOX_HOST}/?console=kvm&novnc=1&vmid=${VM_ID}&vmname=${VMNAME}&node=${NODE}&resize=off&cmd=&vncticket=${VNC_TICKET}"
echo "Open the following URL in your browser to access the VNC console without prior authentication:"
echo $VNC_URL
I thought that this would work, however, it is resulting in "Error 401: No ticket"
Here is the resulting URL:
https://192.168.2.51:8006/?console=...Z0yapSElgVzbKSEUFuMPZvL0qpjdCwjmAnhETKg7H3g==
Would anybody be able to point me in the right direction? It feels so close.
Thanks!