It occurred to me that at some point and time I may want another user account for others to log into the system with. I assume this is not built-in to the software - but I can add it to the code somewhere?
Furthermore, some type of permission wall would be desired so that a user could, for example, view the video stream and look at pictures, but not have the ability to activate any relays/hardware, etc. That way I don't have to worry about my 12 year old nephew dumping all my water. :)
Just thinking out loud!
Thanks.
Adding a new user is still an obstacle for me. I'm trying to understand the way the data is stored and called in order to add another entry. I know the credentials are stored in
`/env/autonom/database/logincred.txt`
and that's serving as the database, where the username/password are checked against. In that file, by default is the value string:
{"name": "login", "password": "REDACTED", "username": "admin"}
I thought it would be simple enough to add another line, same thing, but different username and password:
{"name": "login", "password": "REDACTED", "username": "admin"} {"name": "login", "password": "REDACTED", "username": "newuser"}
But that killed my login abilities, giving me login error for whatever account I tried to use. My understanding is due to keyword collision/conflict as outlined below. Looking at the logic in the code I see the get username and getpassword functions, they use a keytosearch variable titled `username`, and `password`, respectively:
def getusername(): recordkey="name" recordvalue="login" keytosearch="username" dataitem=filestoragemod.searchdata(DATAFILENAME,recordkey,recordvalue,keytosearch) return dataitem def getpassword(): recordkey="name" recordvalue="login" keytosearch="password" dataitem=filestoragemod.searchdata(DATAFILENAME,recordkey,recordvalue,keytosearch) return dataitem
Thinking about what the code is doing, this indicates to me there is a collision in the naming keyword. My thought process says the logincreds.txt file needs to have unique keyword names, such as username2 and password2 - something like this:
{"name": "login", "password": "REDACTED", "username": "admin"} {"name": "login", "password2": "REDACTED", "username2": "newuser"}
The problem I have now is modifying the python code so that it iterates through all username/password combinations? Basically, the logic should say, if I match username admin, then try to match 'this' password. But if not, move on to the next pattern match attempt, and if a match use `that` password. If no match, move on to the next line trying to match username. If by the end of document `logincreds.txt`, no match on username, then 'invalid credentials' is the result.
Just thinking out loud here. Not sure I'll have the time to play with it today.
Thanks.
Upon further inspection, that's not entirely accurate as the function I was modifying was for restoring defaults clearly indicated by the name of the function:
Instead, it looks like the credentials are stored in an obvious "logincred.txt" file, that appears to be created in the current working directory:
I suppose I'll SSH into the pi, navigate to the proper directory (whatever that is - not sure yet), and then append another username and password entry into the logincred.txt file and report back.
Future state, I want to create a new user button in the web interface so entries can be added/deleted from the web GUI.
I also plan on adding a 'tag' or 'attribute' to this user that is checked before every action to determine if a user has 'permissions'. If value 0 = admin, 1 = moderator, 2 = spectator
Alright, looks like the code of interest is found here: https://github.com/Hydrosys4/Master/blob/master/logindbmod.py
Pretty sure I just need to add to the array (or list ;) here:
filedata=[{'name':'login', 'username':'admin','password':'default' }]
But I'm not entirely sure what that would look like. I'm thinking another 'username'/'password' clause in the array should do it. Something like:
filedata=[{'name':'login', 'username':'admin','password':'default', 'username':'newuser','password':'newpassword' }]
I'll do some testing/research and report back.