Author Topic: How to Automate User Account creation?  (Read 10989 times)

0 Members and 1 Guest are viewing this topic.

Offline
*
How to Automate User Account creation?
« on: March 08, 2019, 06:29:02 PM »
Hi there,

Does anyone know of a way to create user accounts from a .csv file?

Offline
***
Re: How to Automate User Account creation?
« Reply #1 on: March 09, 2019, 03:02:50 AM »
Try to use API.

Regards,
Netino

Offline
*
Re: How to Automate User Account creation?
« Reply #2 on: March 12, 2019, 09:50:26 PM »
What API am I to use specifically

Offline
***
Re: How to Automate User Account creation?
« Reply #3 on: March 13, 2019, 02:43:27 AM »
You must use the "account" API, from API Manager, in:
"CWP Settings" >> "API Manager" >> "Account".

You find there an example to use a API in your customized programs.
There are functions add, udp, del, list, susp, unsp to accounts, using method post.

Offline
*
Re: How to Automate User Account creation?
« Reply #4 on: March 13, 2019, 11:35:39 PM »
Could you explain how I would implement that? Sorry im very new to web panels. Here is my goal:

I want to be able to take a .csv file and upload it which will then create user accounts based on the information in the file. I am a visual learner so if you could explain steps on how you would do it that would be really helpful.

Offline
***
Re: How to Automate User Account creation?
« Reply #5 on: March 15, 2019, 04:35:28 AM »
What fields and what format you have in your .csv file..??

Offline
*
Re: How to Automate User Account creation?
« Reply #6 on: March 16, 2019, 12:06:00 AM »
id, username, domain, ip_address, email, setup_date, package, backup

Offline
***
Re: How to Automate User Account creation?
« Reply #7 on: March 16, 2019, 09:53:53 PM »
The fields to "add" function to add accounts using API are the following:
=================================================
key:   Key authorized by Api administrator
action:   add
domain:   main domain associated with the account
user:   username to create
pass:   Password for the account
email:   Email Address of the account owner
package:   Create account with package
inode:   number of inodes allowed
limit_nofile:   limit_nofile
server_ips:   server_ips
=================================================

Ps:
1) Is not possible to preserve Ids from other server with API. Only hardcoded is possible, although not recommended.
2) you don't have passwords in your data file, but passwords are mandatory to the API.
     So, you can add a field to fulfil the password field, or change it to your taste.
3) max lenght of username field is assumed 8 characters lenth, of valid characters to unix usernames.

So, suppose you have your data accounts in a file name 'dataaccounts.csv' in current directory.

Save and run the following script:
Code: [Select]
#!/bin/sh

# Change the following variables
value_key="[YOUR KEY HERE]"
default_password="[DEFAULT PASSWORD]"
password="[PASSWORD]"
your_server="[YOUR-SERVER]" # IP address or domain

while IFS="," read id username domain ip_address email setup_date package backup; do
status=$(curl --data "key=${value_key}" \
--data "action=add" \
--data "domain=${domain}" \
--data "user=${username}" \
--data "pass=${default_password}" \
--data "email=${email}" \
--data "package=${package}" \
--data "inode=0" \
--data "limit_nofile=0" \
--data "server_ips=${ip_address}" \
https://${your_server}:2304/v1/account)

if [[ ${status} -eq 28 ]]; then
echo "... ... Timeout accessing URL: https://${your_server}:2304/v1/account ... !!!"
echo "Timeout accessing URL https://${your_server}:2304/v1/account: More than $timeout seconds trying to access." | \
elif [[ ${status} -eq 6 ]]; then
echo "... ... Error accessing URL: https://${your_server}:2304/v1/account ... !!!"
echo "Error accessing URL https://${your_server}:2304/v1/account: The domain host could not be resolved." | \
elif [[ ${status} -eq 51 ]]; then
echo "... ... Error accessing URL: https://${your_server}:2304/v1/account ... !!!"
error = "Error accessing URL https://${your_server}:2304/v1/account: Could not communicate securely with server:"
error = "${error} The requested domain does not match the server's certificate."
echo ${error}
elif [[ ${status} -gt 0 ]]; then
error = "Error code ${status} has been returned"
echo "${error}"
fi
done < dataaccounts.csv

This script was written in bash, but you can write it too in php, as suggested in CWP API manager.
« Last Edit: March 16, 2019, 10:04:56 PM by Netino »