API Token Login
Add full support for passwordless token-only login.
This commit is contained in:
parent
ad31d37364
commit
f9be014ea2
2
dist/vdiclient.json
vendored
2
dist/vdiclient.json
vendored
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"upgrade_guid" : "46cbad92-353e-4b28-9bee-83950991dad8",
|
"upgrade_guid" : "46cbad92-353e-4b28-9bee-83950991dad8",
|
||||||
"version" : "1.0.7",
|
"version" : "1.0.8",
|
||||||
"product_name" : "VDI Client",
|
"product_name" : "VDI Client",
|
||||||
"manufacturer" : "Josh Patten",
|
"manufacturer" : "Josh Patten",
|
||||||
"name" : "VDI Client",
|
"name" : "VDI Client",
|
||||||
|
@ -22,7 +22,7 @@ auth_backend = pve
|
|||||||
auth_totp = false
|
auth_totp = false
|
||||||
# If disabled, TLS certificate will not be checked
|
# If disabled, TLS certificate will not be checked
|
||||||
tls_verify = false
|
tls_verify = false
|
||||||
# User name
|
# User name (if using token)
|
||||||
#user = user
|
#user = user
|
||||||
# API Token Name
|
# API Token Name
|
||||||
#token_name = dvi
|
#token_name = dvi
|
||||||
|
83
vdiclient.py
83
vdiclient.py
@ -185,9 +185,13 @@ def setmainlayout():
|
|||||||
|
|
||||||
def getvms():
|
def getvms():
|
||||||
vms = []
|
vms = []
|
||||||
for vm in G.proxmox.cluster.resources.get(type='vm'):
|
try:
|
||||||
vms.append(vm)
|
for vm in G.proxmox.cluster.resources.get(type='vm'):
|
||||||
return vms
|
vms.append(vm)
|
||||||
|
return vms
|
||||||
|
except proxmoxer.core.ResourceException as e:
|
||||||
|
win_popup_button(f"Unable to display list of VMs:\n {e!r}", 'OK')
|
||||||
|
return False
|
||||||
|
|
||||||
def setvmlayout(vms):
|
def setvmlayout(vms):
|
||||||
layout = []
|
layout = []
|
||||||
@ -328,7 +332,7 @@ def setcmd():
|
|||||||
win_popup_button('Installation of virt-viewer missing, please install using `apt install virt-viewer`', 'OK')
|
win_popup_button('Installation of virt-viewer missing, please install using `apt install virt-viewer`', 'OK')
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
def pveauth(username, passwd, totp):
|
def pveauth(username, passwd=None, totp=None):
|
||||||
random.shuffle(G.hostpool)
|
random.shuffle(G.hostpool)
|
||||||
err = None
|
err = None
|
||||||
for hostinfo in G.hostpool:
|
for hostinfo in G.hostpool:
|
||||||
@ -361,37 +365,52 @@ def pveauth(username, passwd, totp):
|
|||||||
|
|
||||||
def loginwindow():
|
def loginwindow():
|
||||||
layout = setmainlayout()
|
layout = setmainlayout()
|
||||||
if G.icon:
|
if G.user and G.token_name and G.token_value: # We need to skip the login
|
||||||
window = sg.Window(G.title, layout, return_keyboard_events=True, resizable=False, no_titlebar=G.kiosk, icon=G.icon)
|
popwin = win_popup("Please wait, authenticating...")
|
||||||
else:
|
connected, authenticated, error = pveauth(G.user)
|
||||||
window = sg.Window(G.title, layout, return_keyboard_events=True, resizable=False, no_titlebar=G.kiosk)
|
popwin.close()
|
||||||
while True:
|
if not connected:
|
||||||
event, values = window.read()
|
win_popup_button(f'Unable to connect to any VDI server, are you connected to the Internet?\nError Info: {error}', 'OK')
|
||||||
if event == 'Cancel' or event == sg.WIN_CLOSED:
|
|
||||||
window.close()
|
|
||||||
return False
|
return False
|
||||||
|
elif connected and not authenticated:
|
||||||
|
win_popup_button('Invalid username and/or password, please try again!', 'OK')
|
||||||
|
return False
|
||||||
|
elif connected and authenticated:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
if G.icon:
|
||||||
|
window = sg.Window(G.title, layout, return_keyboard_events=True, resizable=False, no_titlebar=G.kiosk, icon=G.icon)
|
||||||
else:
|
else:
|
||||||
if event in ('Log In', '\r', 'special 16777220', 'special 16777221'):
|
window = sg.Window(G.title, layout, return_keyboard_events=True, resizable=False, no_titlebar=G.kiosk)
|
||||||
popwin = win_popup("Please wait, authenticating...")
|
while True:
|
||||||
user = values['-username-']
|
event, values = window.read()
|
||||||
passwd = values['-password-']
|
if event == 'Cancel' or event == sg.WIN_CLOSED:
|
||||||
totp = None
|
window.close()
|
||||||
if '-totp-' in values:
|
return False
|
||||||
if values['-totp-'] not in (None, ''):
|
else:
|
||||||
totp = values['-totp-']
|
if event in ('Log In', '\r', 'special 16777220', 'special 16777221'):
|
||||||
connected, authenticated, error = pveauth(user, passwd, totp)
|
popwin = win_popup("Please wait, authenticating...")
|
||||||
popwin.close()
|
user = values['-username-']
|
||||||
if not connected:
|
passwd = values['-password-']
|
||||||
win_popup_button(f'Unable to connect to any VDI server, are you connected to the Internet?\nError Info: {error}', 'OK')
|
totp = None
|
||||||
elif connected and not authenticated:
|
if '-totp-' in values:
|
||||||
win_popup_button('Invalid username and/or password, please try again!', 'OK')
|
if values['-totp-'] not in (None, ''):
|
||||||
elif connected and authenticated:
|
totp = values['-totp-']
|
||||||
window.close()
|
connected, authenticated, error = pveauth(user, passwd=passwd, totp=totp)
|
||||||
return True
|
popwin.close()
|
||||||
#break
|
if not connected:
|
||||||
|
win_popup_button(f'Unable to connect to any VDI server, are you connected to the Internet?\nError Info: {error}', 'OK')
|
||||||
|
elif connected and not authenticated:
|
||||||
|
win_popup_button('Invalid username and/or password, please try again!', 'OK')
|
||||||
|
elif connected and authenticated:
|
||||||
|
window.close()
|
||||||
|
return True
|
||||||
|
#break
|
||||||
|
|
||||||
def showvms():
|
def showvms():
|
||||||
vms = getvms()
|
vms = getvms()
|
||||||
|
if vms == False:
|
||||||
|
return False
|
||||||
if len(vms) < 1:
|
if len(vms) < 1:
|
||||||
win_popup_button('No desktop instances found, please consult with your system administrator', 'OK')
|
win_popup_button('No desktop instances found, please consult with your system administrator', 'OK')
|
||||||
return False
|
return False
|
||||||
@ -445,12 +464,16 @@ def main():
|
|||||||
if not loggedin:
|
if not loggedin:
|
||||||
loggedin = loginwindow()
|
loggedin = loginwindow()
|
||||||
if not loggedin:
|
if not loggedin:
|
||||||
|
if G.user and G.token_name and G.token_value: # This means if we don't exit we'll be in an infinite loop
|
||||||
|
return 1
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
vmstat = showvms()
|
vmstat = showvms()
|
||||||
if not vmstat:
|
if not vmstat:
|
||||||
G.proxmox = None
|
G.proxmox = None
|
||||||
loggedin = False
|
loggedin = False
|
||||||
|
if G.user and G.token_name and G.token_value: # This means if we don't exit we'll be in an infinite loop
|
||||||
|
return 0
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
sys.exit(main())
|
sys.exit(main())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user