def rand_reset(device_ip, admin_username, admin_pass): """ Replace all non-admin users passwords with randomly generated passwords. Return the changed passwords. """ ex = PacketmasterEX(device_ip, admin_username, admin_pass) results = {} changes = {} if ex.conn_test() == "Connection established": results["conn"] = True else: results["conn"] = False return results user_list = ex.get_users() data = json.loads(user_list) for user in data: if user != admin_username: rand_pass = rand_generator() changes[user + "@" + device_ip] = { "device": device_ip, "username": user, "password": rand_pass } ex.mod_user(data[user]["username"], data[user]["username"], data[user]["accesslevel"], rand_pass, data[user]["description"], data[user]["radius"]) results["users"] = changes return results
def admin_reset(device_ip, admin_username, admin_pass): """ Replace only admin users password with randomly generated password and return the new password. """ ex = PacketmasterEX(device_ip, admin_username, admin_pass) results = {} changes = {} if ex.conn_test() == "Connection established": results["conn"] = True else: results["conn"] = False return results cur_users = ex.get_users() data = json.loads(cur_users) rand_pass = rand_generator() changes[admin_username + "@" + device_ip] = { "device": device_ip, "username": admin_user, "password": rand_pass } ex.mod_user(data[admin_username]["username"], data[admin_username]["username"], data[admin_username]["accesslevel"], rand_pass, data[admin_username]["description"]) results["users"] = changes return results
def file_reset(device_ip, admin_username, admin_pass, user_list): """ Reset non-admin user passwords using a provided username and password list. """ ex = PacketmasterEX(device_ip, admin_username, admin_pass) results = {} if ex.conn_test() == "Connection established": results["conn"] = True else: results["conn"] = False return results to_change = [] cur_users = ex.get_users() data = json.loads(cur_users) for user in data: to_change.append(user) for user in user_list: if user["username"] in to_change and user["username"] != admin_username: key = user["username"] ex.mod_user(data[key]["username"], data[key]["username"], data[key]["accesslevel"], user["passwd"], data[key]["description"], data[key]["radius"]) return results