Update a user's config using API with PHP DA Class

akymakr

Verified User
Joined
Oct 15, 2011
Messages
20
Location
Hong Kong
When I update a user's configuration, I used the following code:

$sock->set_method('POST');
$sock->query('/CMD_API_MODIFY_USER',
array(
'action' => 'customize',
'user' => "$cpusername",
'bandwidth' => "$whBan",
'ubandwidth' => "$uBan",
'quota' => "$whDis",
'uquota' => "$uDis",
'vdomains' => "$whDom",
'uvdomains' => "$uDom",
'nemails' => "$whEml",
'unemails' => "$uEml",
'mysql' => "$whSql",
'umysql' => "$uSql",
'ftp' => "$whFtp",
'uftp' => "$uFtp",
'package' => "$backend"
));

Those $wh are $_POST variables.
Then I have made a if else condition (if diskspace = 0, $uDis = "ON")
so in case of I want to give unlimited diskspace, it should finally set to unlimited.
But it didn't go like plan.

If something is set to ON, everything will be ON (that means all settings will be changed to unlimited)
I have tried to separate them to query twice but the same result.

Was my code's problem?
 
Hello,

How does your code look like with the IF statements? From your description I might conclude you've got an error in coding.

Keep in mind to check it here: http://directadmin.com/api.html and check with FireBug in Firefox how and what variables are send from /CMD_MODIFY_USER in Directadmin. You should do the same with /CMD_API_MODIFY_USER.

Note, you probably do not need to sent:

'ubandwidth' => "$uBan",

if you don't want to use unlimited bandwidth. The same might be true for other options as for a browser does not sent unticked checkboxes in POST/GET request.
 
Here is my if statement:

PHP:
        if($whDis == 0) { $uDis = "ON"; } else { $uDis = "OFF"; }
        $whBan = $_POST["bandwidth"];
        if($whBan == 0) { $uBan = "ON"; } else { $uBan = "OFF"; }
        $whDom = $_POST["domain"];
        if($whDom == 999) { $uDom = "ON"; } else { $uDom = "OFF"; }
        $whEml = $_POST["email"];
        if($whEml == 999) { $uEml = "ON"; } else { $uEml = "OFF"; }
        $whFtp = $_POST["ftp"];
        if($whFtp == 999) { $uFtp = "ON"; } else { $uFtp = "OFF"; }
        $whSql = $_POST["mysql"];
        if($whSql == 999) { $uSql = "ON"; } else { $uSql = "OFF"; }

$wh___ is the number i input.
$u___ is to determine "ON" or "OFF"

Details:
If i input 0 to the input type text before post in Diskspace or Bandwidth, that means I actually want to give unlimited to the user so uDis or uBan should be ON.
For Domain, Email Accounts, FTP, MySQL. You may know that is meaningless for me to give a people 999 of domains. So if I set the number to 999 that means unlimited, uDom, uEml ... should be set to "ON"

That's my logic of the code, so it must have a variable when query.
Thank you for your help in advance and sorry for my poor English.
 
Last edited by a moderator:
Try to remove from

$sock->query('/CMD_API_MODIFY_USER',
array(
...
));

those lines starting with 'u which have OFF as value. I mean do not sent OFF Values, only ON if it is to be set to unlimited.
 
I found that "unlimited" is an acceptable value.
So if diskspace=0, diskspace=unlimited and put it in array 'quota' => 'diskspace' works!!!
 
Back
Top