API - Create new user failed!

mauer

New member
Joined
Dec 29, 2007
Messages
1
Hi there,

I want to make an script to add accounts to my Directadmin servers. I want to use the httpsocket script: http://www.l0rdphi1.com/tools/httpsocket/httpsocket.phps .
PHP:
<?php 

function onoff($num){ 
if($num == 1){ 
return ON; 
}else{ 
return OFF; 
} 
} 





$packageinfo     = packageinfo( 'Product_id', $_POST['Package'] ); 
$userinfo = $class_debiteur->userinfo('DebtorCode', $_POST['Debtor']); 


switch($packageinfo['PackageType']){ 
case 1: 
$query = '/CMD_API_ACCOUNT_USER'; 
break; 
case 2: 
$query = '/CMD_API_ACCOUNT_RESELLER'; 
break; 
} 


$username    = $_POST['Username']; 
$email         = $userinfo['EmailAddress']; 
$passwd        = $_POST['Password']; 
$domain        = $_POST['Domain']; 
$package    = $packageinfo['Package']; 
$status        = $_POST['Status']; 


//nu gaan we inloggen in Direct Admin (verander wel de gegevens)  
$sock->connect('urlofip',2222);  
$sock->set_login('gebruikersnaam','wachtwoord');  

$sock->set_method('POST');  
$sock->query($query, array( 
'action'             => 'create', 
'add'                => 'Submit', 
'username'            => $username, 
'email'                => $email, 
'passwd'            => $passwd, 
'passwd2'            => $passwd, 
'domain'            => $domain, 
'bandwidth'            => $packageinfo['Bandwidth'], 
'ubandwidth'                => onoff($packageinfo['uBandwidth']), 
'quota'                => $packageinfo['Space'], 
'uquota'            => onoff($packageinfo['uSpace']), 
'vdomains'            => $packageinfo['Domains'], 
'uvdomains'            => onoff($packageinfo['uDomains']), 
'nsubdomains'                => $packageinfo['SubDomains'], 
'unsubdomains'                => onoff($packageinfo['uSubDomains']), 
'nemails'            => $packageinfo['EmailAccounts'], 
'unemails'            => onoff($packageinfo['uEmailAccounts']), 
'nemailf'            => $packageinfo['EmailForwarders'], 
'unemailf'            => onoff($packageinfo['uEmailForwarders']), 
'nemailml'            => $packageinfo['MailingLists'], 
'unemailml'            => onoff($packageinfo['uMailingLists']), 
'nemailr'            => $packageinfo['AutoResponders'], 
'unemailr'            => onoff($packageinfo['uAutoResponders']), 
'mysql'                => $packageinfo['MySQLDatabases'], 
'umysql'            => onoff($packageinfo['uMySQLDatabases']), 
'domainptr'            => $packageinfo['DomainPointers'], 
'udomainptr'                => onoff($packageinfo['uDomainPointers']), 
'ftp'                => $packageinfo['FTPAccounts'], 
'uftp'                => onoff($packageinfo['uFTPAccounts']), 
'aftp'                => onoff($packageinfo['AnonymousFTP']), 
'cgi'                => onoff($packageinfo['CGIAccess']), 
'php'                => onoff($packageinfo['PHPAccess']), 
'ssl'                => onoff($packageinfo['SSLAccess']), 
'ssh'                => onoff($packageinfo['SSHAccess']), 
'dnscontrol'                => onoff($packageinfo['DNSControl']), 
'ip'                => '195.xxx.xxx.xxx', 
'notify'            => 'no' 


));  

$result = $sock->fetch_body();  
echo $result; 

?>
All the package info is saved in a mysql databsse, bandwidth = 1500 ,ubandwidth = 0 ( 0 = off, 1 = on).

DirectAdmin makes an account, but when I look in the configuration screen I see that the bandwidth unlimited is. And the problem is not only the bandwidth but with all variables! Who can tell me what te problem is?
 
This one works fine!

PHP:
<?php

$username 	= $_POST[username];
$email 		= $_POST[email];
$passwd 	= $_POST[password1];
$passwd2 	= $_POST[password2];
$domain 	= $_POST[domain];
$bandwidth 	= $_POST[bandwidth];
$ubandwidth 	= $_POST[ubandwidth];
$quota 		= $_POST[quota];
$uquota 	= $_POST[uquota];
$vdomains 	= $_POST[vdomains];
$uvdomains 	= $_POST[uvdomains];
$nsubdomains 	= $_POST[nsubdomains];
$unsubdomains 	= $_POST[unsubdomains];
$ips 		= $_POST[ips];
$nemails 	= $_POST[nemails];
$unemails 	= $_POST[unemails];
$nemailf 	= $_POST[nemailf];
$unemailf 	= $_POST[unemailf];
$nemailml 	= $_POST[nemailml];
$unemailml 	= $_POST[unemailml];
$nemailr 	= $_POST[nemailr];
$unemailr 	= $_POST[unemailr];
$mysql 		= $_POST[mysql];
$umysql 	= $_POST[umysql];
$domainptr  	= $_POST[domainptr];
$udomainptr 	= $_POST[udomainptr];
$ftp 		= $_POST[ftp];
$uftp 		= $_POST[uftp];
$aftp 		= $_POST[aftp];
$cgi 		= $_POST[cgi];
$ssl 		= $_POST[ssl];
$ssh 		= $_POST[ssh];
$dnscontrol 	= $_POST[dnscontrol];
$dns		= $_POST[dns];
$ip		= $_POST[ip];
$notify 	= $_POST[notify];

include './config.php';
include 'inc/httpsocket.php';

$sock = new HTTPSocket;
$sock->connect('ipaddress',2222);

$sock->set_login('loginname','password');

$sock->set_method('POST');

$sock->query('/CMD_API_ACCOUNT_USER',
    array(
        'username' => $username, // The User's username. 4-8 characters, alphanumeric
        'email' => $email, // A valid email address
        'passwd' => $password1, // The User's password. 5+ characters, ascii
        'passwd2' => $password2, // Password double check. 5+ characters, ascii
        'domain' => $domain, // A valid domain name in the form: domain.com
        'bandwidth' => $bandwidth, // Amount of bandwidth Reseller will be allowed to use. Number, in Megabytes
        'ubandwidth' => $ubandwidth, // ON or OFF. If ON, bandwidth is ignored and no limit is set
        'quota' => $quota, // Amount of disk space Reseller will be allowed to use. Number, in Megabytes
        'uquota' => $uquota, // ON or OFF. If ON, quota is ignored and no limit is set
        'vdomains' => $vdomains, // Number of domains the reseller and his/her User's are allowed to create
        'uvdomains' => $uvdomains, // ON or OFF. If ON, vdomains is ignored and no limit is set
        'nsubdomains' => $nsubdomains, // Number of subdomains the reseller and his/her User's are allowed to create
        'unsubdomains' => $unsubdomains, // ON or OFF. If ON, nsubdomains is ignored and no limit is set
        'ips' => $ips, // Number of ips that will be allocated to the Reseller upon account during account
        'nemails' => $nemails, // Number of pop accounts the reseller and his/her User's are allowed to create
        'unemails' => $unemails, // ON or OFF Unlimited option for nemails
        'nemailf' => $nemailf, // Number of forwarders the reseller and his/her User's are allowed to create
        'unemailf' => $unemailf, // ON or OFF Unlimited option for nemailf
        'nemailml' => $nemailml, // Number of mailing lists the reseller and his/her User's are allowed to create
        'unemailml' => $unemailml, // ON or OFF Unlimited option for nemailml
        'nemailr' => $nemailr, // Number of autoresponders the reseller and his/her User's are allowed to create
        'unemailr' => $unemailr, // ON or OFF Unlimited option for nemailr
        'mysql' => $mysql, // Number of MySQL databases the reseller and his/her User's are allowed to create
        'umysql' => $umysql, // ON or OFF Unlimited option for mysql
        'domainptr' => $domainptr, // Number of domain pointers the reseller and his/her User's are allowed to create
        'udomainptr' => $udomainptr, // ON or OFF Unlimited option for domainptr
        'ftp' => $ftp, // Number of ftp accounts the reseller and his/her User's are allowed to create
        'uftp' => $uftp, // ON or OFF Unlimited option for ftp
        'aftp' => $aftp, // ON or OFF If ON, the reseller and his/her users will be able to have anonymous ftp accounts.
        'cgi' => $cgi, // ON or OFF If ON, the reseller and his/her users will be have the ability to run cgi scripts in their cgi-bins.
        'ssl' => $ssl, // ON or OFF If ON, the reseller and his/her users will be have the ability to access their websites through secure https://.
        'ssh' => $ssh, // ON or OFF If ON, the reseller will be have an ssh account.
        'dnscontrol' => $dnscontrol, // ON or OFF If ON, the reseller will be able to modify his/her dns records and to create users with or without this option
        'dns' => $dns, // OFF or TWO or THREE. If OFF, no dns's will be created. TWO: domain ip for ns1 and another ip for ns2. THREE: domain has own ip. ns1 and ns2 have their own ips
        'ip' => $ipaddress, // shared or assign. If shared, domain will use the server's main ip. assign will use one of the reseller's ips
        'notify' => $notify, // yes or no. If yes, an email will be sent to email
        'action' => 'create',
        'add' => 'Submit'
    ));
$result = $sock->fetch_parsed_body();

if ( $sock->get_status_code() != 200 || !empty($result['error']) )
{
    // failure.
    echo "Failed to add new custom user: {$result['text']}<br />{$result['details']}";
} else {
    // new user added.
    print_r('Custom user '.$username.' created...');
}


?>
 
Back
Top