dim virtviewer,proxmoxhost,username,password,vmid,node
virtviewer="C:\Program Files\VirtViewer v11.0-256\bin\virt-viewer.exe"
proxmoxhost="proxmox.lan:8006"
username="root" '"root@pam"
password="XXXXXXX"
node="pam"
vmid="101"
Dim NamedArgs, UnnamedArgs, x
Set NamedArgs = WScript.Arguments.Named
Set UnnamedArgs = WScript.Arguments.Unnamed
'should only execute on missing parameters
msgbox "-u username. Default root@pam" & vbcrlf & _
"-p password. Default ''" & vbcrlf & _
"vmid: id for VM" & vbcrlf & _
"node: Proxmox cluster node name" & vbcrlf & _
"proxy: DNS or IP (use <node> as default)"
Dim ServerName, WorkstationName
For Each Arg In NamedArgs
Select Case Arg
Case "-u", "--username"
username = NamedArgs.Item(Arg)
Case "-p", "--password"
password = NamedArgs.Item(Arg)
End Select
Next
For x = 0 To UnnamedArgs.Count - 1
if x = 0 then vmid=UnnamedArgs.Item(x)
if x = 1 then node=UnnamedArgs.Item(x)
if x = 2 then proxmoxhost=UnnamedArgs.Item(x)
Next
dim strRequest,proxmoxserverurl
strRequest="username%3D" & username & "%40pam%2password%3D" & password
proxmoxserverurl = "https://" & proxmoxhost & "/api2/json/access/ticket"
dim http
set http=createObject("Microsoft.XMLHTTP")
http.open "POST",proxmoxserverurl,false
http.setRequestHeader "Content-Type","application/json"
'http.setRequestHeader "X-Parse-Application-Id","XXXXXXXXXXXXXXXXXXXXX"
msgbox proxmoxserverurl & vbcrlf & strRequest
' this should be equivalent to DATA="$(curl -f -s -S -k --data-urlencode "username=$USERNAME" --data-urlencode "password=$PASSWORD" "https://$PROXY:8006/api2/json/access/ticket")"
http.send strRequest
' need to actually do something with this
If http.Status = 200 Then
msgbox "RESPONSE : " & http.responseText
responseText=http.responseText
else
msgbox "ERRCODE : " & http.status
End If
'bash string parsing looks like a cat walking on a keyboard, why do 1980s programmers like punctuations more than the alphabet,
'convert to human readable vbs, it would really help to see what TICKET and CSRF are supposed to look like
'TICKET="${DATA//\"/}"
'TICKET="${TICKET##*ticket:}"
'TICKET="${TICKET%%,*}"
'TICKET="${TICKET%%\}*}"
'CSRF="${DATA//\"/}"
'CSRF="${CSRF##*CSRFPreventionToken:}"
'CSRF="${CSRF%%,*}"
'CSRF="${CSRF%%\}*}"
'strRequest="username%3D" & username & "%0Apassword%3D" & password
'proxmoxserverurl = "https://" & proxmoxhost & "/api2/json/access/ticket"
set http=createObject("Microsoft.XMLHTTP")
http.open "POST",proxmoxserverurl,false
http.setRequestHeader "Content-Type","application/json"
' convert below to
' curl -f -s -S -k -b "PVEAuthCookie=$TICKET" -H "CSRFPreventionToken: $CSRF" "https://$PROXY:8006/api2/spiceconfig/nodes/$NODE/qemu/$VMID/spiceproxy" -d "proxy=$PROXY" > spiceproxy
msgbox proxmoxserverurl & vbcrlf & strRequest
http.send strRequest
' need to actually do something with this
If http.Status = 200 Then
msgbox "RESPONSE : " & http.responseText
responseText=http.responseText
else
msgbox "ERRCODE : " & http.status
End If
dim parameters
' need the above code to work before I can decode it back into virtviewer parameters
Set objShell = CreateObject("Shell.Application")
objShell.ShellExecute "virtviewer", parameters, "", "runas", 1