Web based account creation

Status
Not open for further replies.

reedjasonf

Dabbler
Joined
Mar 12, 2013
Messages
21
Hello,

So here is what I'm trying to do: I would like to develop a fairly simple web interface for users to be able to create their own account for our share running FreeNAS. This way, each user can create their own account and choose their own password instead of me having to go into the FreeNAS gui and create everyone's account and assign them a password.

I thought I could do this easily with PHP and SSH by writting php instructions that would log into the shell with ssh, create the user, add them to a group, and set their password. I was able to log into freenas by SSH and create users and groups but those users and groups did not show up in the GUI. Also, after a few minutes those groups and users that I manually created through the shell had disappeared. Why? When creating users and groups I used:
Code:
pw adduser -u 1476 -n <username> -g 1002 -c "John Doe" -d /nonexistent

and
Code:
pw modgroup 1002 -m 1476


Was I doing something wrong or is FreeNAS set up to store user, group, and password information somewhere different then the pw command? Where can I see the commands the GUI sends to the OS when it creates new users? I don't care to do anything with homegroups. I just need to make the accounts show up in the GUI and let the user set their own password.
 

warri

Guru
Joined
Jun 6, 2011
Messages
1,193
I think FreeNAS is additionally storing the users in its internal database. You might have to call the appropriate function in the freenas code base to cleanly create a user, but I don't know where exactly it sits.

Update: Maybe start looking in the forms.py of the GUI: gui/account/forms.py
 

reedjasonf

Dabbler
Joined
Mar 12, 2013
Messages
21
Yeah I found this in the FreeNAS gui but it's really confusing for someone who hasn't ever dealt with python before. Anyone that can translate this a little bit? I have some knowledge of C/C++ and can somewhat understand the classes but I don't understand how or where these class definitions are used when submitting the Add New User Form.
 

ProtoSD

MVP
Joined
Jul 1, 2011
Messages
3,348
I don't think you really need to figure out what's happening with Python. Use sqlite3, dump the database and see the structure of how users are stored, create your users from the command line like you were doing, and add/update the entries in the database.

EDIT: Make a copy of the database (/data/freenas-v1.db) and then use this app to browse it:

http://sqlitebrowser.sourceforge.net/
 

cyberjock

Inactive Account
Joined
Mar 25, 2012
Messages
19,526
Warri is right. Several people have manually created users from the command line and then asked why the database hasn't been updated. Nothing "bad" will happen if the FreeNAS internal database doesn't match FreeBSD, but some permissions you may want to set won't work quite right since the FreeNAS database won't know the users exist.
 

reedjasonf

Dabbler
Joined
Mar 12, 2013
Messages
21
Never felt this stupid and confused in my life....

I was able to copy the /data/freenas-v1.db file and view the structure of the database - which is great!
However, now I have two problems. The first is that there are two fields which I guess the first (bsdusr_unixhash) is the user's password. The second (bsdusr_smbhash) I think I have found the python function for generating that. I think it's pdbedit, right?

I can't find out how the system makes the bsdusr_unixhash. At first I thought it might be a simple md5 hash with a salt. Like using the crypt() function but I don't think that's what it is.

I also need to know, is there an easy way to connect to the database and insert rows from another computer? Somehow I'll have to have access to the /data/freenas-v1.db in order to make changes.
To the above statement, I've figured out that I could just use the sqlite3 command in the shell to open and edit that file.
 

reedjasonf

Dabbler
Joined
Mar 12, 2013
Messages
21
Alright!!! I figured it out. The bsduser_unixhash IS an md5 hash. The salt is everything after $1$ to the first period. (Duh!) So if I'm asking people for their password and going to insert it directly into the db I'm going to use crypt($password, '<myhash>'); in php to generate it.

Thanks guys!
 
Status
Not open for further replies.
Top