From the mind of a G33k

FreeNAS Bulk Add Python script
FreeNAS Bulk Add Python script

FreeNAS Bulk Add user python script

    Want to add more than one user at a time on your FreeNAS server? You've come to the right place here is the python script to do it!

import json,csv
import requests


usertemplate = {
  'bsdusr_uid': '1100',
  'bsdusr_username': '',
  'bsdusr_mode': '755',
  'bsdusr_creategroup': 'True',
  'bsdusr_password': '',
  'bsdusr_shell': '/usr/local/bin/bash',
  'bsdusr_full_name': '',
  'bsdusr_email': '',
}
def read_cell(x, y):
    with open('new_users.csv', 'r') as f:
        reader = csv.reader(f)
        y_count = 0
        for n in reader:
            if y_count == y:
                cell = n[x]
                return cell
            y_count += 1
print (read_cell(1, 0))



i = 0
id = 1200
with open("new_users.csv","r") as f:
    for line in f:
        usertemplate["bsdusr_full_name"] = read_cell(0, i)
        usertemplate["bsdusr_password"] = read_cell(1, i)
        usertemplate["bsdusr_home"] = read_cell(2, i)
        usertemplate["bsdusr_uid"] = id
        usertemplate['bsdusr_username'] = read_cell(0, i)
        r = requests.post(
          'http://192.168.168.138/api/v1.0/account/users/',
          auth=('root', 'password'),
          headers={'Content-Type': 'application/json'},
          verify=False,
          data=json.dumps(usertemplate)
        )
        print(r.text)
        i +=1
        id +=1

Download File: .:. lgfnblkadd.py .:.