I am wanting to setup an auto login based on the client IP address. Using if statements I can auto login the user and open the correct window for the client. It will become very cumbersome to keep up with as more clients are added. I have created a MySQL table setup with each clients IP address the username, login and startup window. How do I pull the info from the table to check the IP against the client IP then use the logon username, password and window?
Not sure if reviving old threads in frowned upon here. Currently everybody gettings automatically logged in as "operator" but I used the code from this page to auto login technicians with matching hostnames to a higher access level. People get an index out of range error if they launch Ignition and aren't in the list.
If there a way to get around having to enter everyone's computer host names and just elevate the ones in the list? I mean it works for people that are listed in the database now but people not in the list get that "index out of range" error on the third line of this code
hostname = system.tag.read("[System]Client/Network/Hostname").value
query = """SELECT username, userpass, userwindow FROM client_list WHERE hostname=?"""
userInfo = system.db.runPrepQuery(query,[hostname])[0]
if system.security.switchUser(userInfo["username"],userInfo["userpass"]):
print("Login Successful")
If the queryResult is empty then you will get an "index out of range" error.
You can check the length of the queryResult and test it to determine if there is data before attempting to use it.
queryResult = system.db.runPrepQuery(query,[hostname])
if len(queryResult) == 0:
#figure out what you want to do if the hostname is not in the database and do it here
return
userInfo = queryResult[0]
[...]