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
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										27
									
								
								vdiclient.py
									
									
									
									
									
								
							
							
						
						
									
										27
									
								
								vdiclient.py
									
									
									
									
									
								
							@ -185,9 +185,13 @@ def setmainlayout():
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
def getvms():
 | 
					def getvms():
 | 
				
			||||||
	vms = []
 | 
						vms = []
 | 
				
			||||||
 | 
						try:
 | 
				
			||||||
		for vm in G.proxmox.cluster.resources.get(type='vm'):
 | 
							for vm in G.proxmox.cluster.resources.get(type='vm'):
 | 
				
			||||||
			vms.append(vm)
 | 
								vms.append(vm)
 | 
				
			||||||
		return vms
 | 
							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,6 +365,19 @@ def pveauth(username, passwd, totp):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
def loginwindow():
 | 
					def loginwindow():
 | 
				
			||||||
	layout = setmainlayout()
 | 
						layout = setmainlayout()
 | 
				
			||||||
 | 
						if G.user and G.token_name and G.token_value: # We need to skip the login
 | 
				
			||||||
 | 
							popwin = win_popup("Please wait, authenticating...")
 | 
				
			||||||
 | 
							connected, authenticated, error = pveauth(G.user)
 | 
				
			||||||
 | 
							popwin.close()
 | 
				
			||||||
 | 
							if not connected:
 | 
				
			||||||
 | 
								win_popup_button(f'Unable to connect to any VDI server, are you connected to the Internet?\nError Info: {error}', 'OK')
 | 
				
			||||||
 | 
								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:
 | 
							if G.icon:
 | 
				
			||||||
			window = sg.Window(G.title, layout, return_keyboard_events=True, resizable=False, no_titlebar=G.kiosk, icon=G.icon)
 | 
								window = sg.Window(G.title, layout, return_keyboard_events=True, resizable=False, no_titlebar=G.kiosk, icon=G.icon)
 | 
				
			||||||
		else:
 | 
							else:
 | 
				
			||||||
@ -379,7 +396,7 @@ def loginwindow():
 | 
				
			|||||||
					if '-totp-' in values:
 | 
										if '-totp-' in values:
 | 
				
			||||||
						if values['-totp-'] not in (None, ''):
 | 
											if values['-totp-'] not in (None, ''):
 | 
				
			||||||
							totp = values['-totp-']
 | 
												totp = values['-totp-']
 | 
				
			||||||
				connected, authenticated, error = pveauth(user, passwd, totp)
 | 
										connected, authenticated, error = pveauth(user, passwd=passwd, totp=totp)
 | 
				
			||||||
					popwin.close()
 | 
										popwin.close()
 | 
				
			||||||
					if not connected:
 | 
										if not connected:
 | 
				
			||||||
						win_popup_button(f'Unable to connect to any VDI server, are you connected to the Internet?\nError Info: {error}', 'OK')
 | 
											win_popup_button(f'Unable to connect to any VDI server, are you connected to the Internet?\nError Info: {error}', 'OK')
 | 
				
			||||||
@ -392,6 +409,8 @@ def loginwindow():
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
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