Hi there, im using the above command to generate multiple user-accounts, using packages already on the server, and taking the settings from a couple of CSV files.
Now the problem im having is that the accounts are created but the limits used by the various packages are not set.
Is there something i need to run after the command is sent
Here is the code i use, with the da-connect-class.php
Find attached an example screenshot of a user setup with this script
Now the problem im having is that the accounts are created but the limits used by the various packages are not set.
Is there something i need to run after the command is sent
Here is the code i use, with the da-connect-class.php
PHP:
<?
include('da-connect-class.php');
//DirectAdmin Default Settings
$GLOBALS['da_port'] = 2222;
$GLOBALS['da_socket'] = null;
/*-----------get server settings-----------*/
//hostname,ip,notify,reseller
$handle = fopen("server_settings.txt", "r");
$serv_settings = fgetcsv($handle, 1000, ",");
fclose($handle);
$GLOBALS['da_host'] = $serv_settings[0];
$GLOBALS['ip'] = $serv_settings[1];
$GLOBALS['notify'] = $serv_settings[2];
$GLOBALS['reseller'] = $serv_settings[3];
$GLOBALS['reseller_pass'] = $serv_settings[4];
/*-----------end get server settings-----------*/
/*-----------get User Accounts-----------*/
//userdomain,email,package|userdomain2,email2,package
$handle = fopen("accounts.txt", "r");
//setting the char limit at 50000, this may need to be edited depending
//on how many users are being added at one time
$accounts = fgetcsv($handle, 50000, "|");
//Each member of the array $accounts will be a an comma seperate string of
//the user settings
fclose($handle);
/*-----------end get user accounts-----------*/
/*--Debug Information--*/
print "The following data was found\n
In settings.txt:\n
DA_Host: ".$GLOBALS['da_host']."\n
IP: ".$GLOBALS['ip']."\n
Notify: ".$GLOBALS['notify']."\n
Reseller: ".$GLOBALS['reseller']."\n\n
In accounts.txt:\n
";
print "=========================================================\n";
for ( $i = 0; $i<count($accounts); $i++ )
{
$tmparray = $accounts[$i];
$array = explode(",",$tmparray);
$userdomain = $array[0];
$email = $array[1];
$package = $array[2];
$password = createRandomPassword();
$offset = 0;
$offset = strpos($userdomain, '.');
$username = substr($userdomain, 0, $offset);
$length = strlen($username);
/*--If a user's domain is under 5 characters in length, two 0's are appended to the domain--*/
if ($length<5){
$username .="00";
}
/*--Sets the upperlimit of 8 chars for the possible username--*/
elseif ($length>8){
$username = substr($userdomain,0, 9);
}
/*--Echo'ed to the command line to provide the creator with the account information in addition to the emails sent out--*/
echo $username."\n";
echo $password."\n";
echo $userdomain."\n";
echo $email."\n";
echo $package."\n";
$value = add_directadmin_account($username, $password, $userdomain, $email, $package);
if ($value==0){
print "
Domain: " . $userdomain ."\tEmail: ".$email."\tPackage: ".$package."\n
Username: ".$username."\tPassword: ".$password."\n";
print"\$value:\t$value\n";
print "=========================================================\n";
}
else {
print"Account Failed to Add";
}
}
function add_directadmin_account($username, $password, $domain, $email, $package)
{
/*
'action' =>'create',
'username' =>'userloginlol',
'email' =>'[email protected]',
'passwd' =>'passwrdw',
'passwd2' =>'passwrdw',
'domain' =>'testtesttest.XXXXX.com',
'package' =>'dsagfsdg',
'ip' =>'xx.xxx.xxx.xx',
'notify' =>'yes'
*/
/* if($quota == -1)
$quota = $GLOBALS['da_quota'];*/
//make sure we have a directadmin connection
directadmin_connect();
$GLOBALS['da_socket']->
query("/CMD_ACCOUNT_USER", array(
"action" =>"create",
"username" => $username,
"email" => $email,
"passwd" => $password,
"passwd2" => $password,
"domain" =>$domain,
"package" => $package,
"ip" => $GLOBALS['ip'],
"notify" => $GLOBALS['notify'],
));
$result = $GLOBALS['da_socket']->
fetch_parsed_body();
//0 == success, account created
// if($result['error'] != 0)
// die("Couldn't create email account: ". $result['text'] . "\n");
} //}}}
function createRandomPassword(){
$chars = "abcdefghijkmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ023456789@#!";
srand((double)microtime()*1000000);
$i = 0;
$pass = '' ;
while ($i<= 8) {
$num = rand() % 33;
$tmp = substr($chars, $num, 1);
$pass = $pass . $tmp;
$i++;
}
return $pass;
}
?>
Find attached an example screenshot of a user setup with this script