Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import accounts #38

Open
Tempokgs opened this issue May 23, 2023 · 1 comment
Open

Import accounts #38

Tempokgs opened this issue May 23, 2023 · 1 comment

Comments

@Tempokgs
Copy link

how to import logins, passwords, email from a file? over 1000 accounts.

@skjh-jewel
Copy link

You can create a python3 script e.g., batch_import.py with below code and put the csv file in same folder and run in from Ubuntu terminal.

change some parameter based on your requirement e.g., radiusdesk_IP, csv file path and name (here it is users.csv) and API token from radiusdesk.

then run command: sudo python3 batch_import.py

import csv
import json
import requests
from datetime import datetime

# RADIUSdesk API endpoint URL
api_url = "http://<radiusdesk_IP>/cake4/rd_cake/permanent-users/add.json"

# CSV file path
csv_file_path = "users.csv"

# Read and process CSV data
with open(csv_file_path, "r") as csv_file:
    csv_reader = csv.reader(csv_file)
    next(csv_reader)  # Skip header row

    for row in csv_reader:
        username, name, surname, profile, phone, email, address, password, to_date = row

        today = datetime.today().strftime("%m/%d/%Y")

        data = {
            "user_id": 0,
            "cloud_id": 23, # Can be found from RADIUSdesk
            "realm": "<realm name goes here>",
            "profile": profile,
            "token": "<API token goes here>",
            "language": "4_4",
            "from_date": today,
            "to_date": to_date,
            "name": name,
            "surname": surname,
            "phone": phone,
            "email": email,
            "address": address,
            "username": username,
            "password": password,
            "active":1,
        }

        headers = {
            "Content-Type": "application/json"
        }

        # Send POST request
        response = requests.post(api_url, data=json.dumps(data), headers=headers, verify=False)

        if response.status_code == 200:
            api_response = response.json()
            if api_response.get("success"):
                print(f"Record for {username} uploaded successfully.")
            else:
                print(f"Error uploading record for {username}: {api_response.get('message')}")
        else:
            print(f"Failed to upload record for {username}. Status code: {response.status_code}")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants