1. Please take a little time for this simple survey! Thank you for participating!
    Dismiss Notice
  2. Dear Pleskians, please read this carefully! New attachments and other rules Thank you!
    Dismiss Notice
  3. Dear Pleskians, I really hope that you will share your opinion in this Special topic for chatter about Plesk in the Clouds. Thank you!
    Dismiss Notice

Plesk RPC API -> packet/client/set/values/limits

Discussion in 'Plesk for Linux - 8.x and Older' started by KulM, Mar 22, 2005.

  1. KulM

    KulM Guest

    0
     
    I am trying to change the limits of a client account and am seeing strange results. I have written a program to change all the limits for an account... everything works fine except when I try and set the disk_space, max_traffic, and mbox_quota get set to 0 even though I have other values specified. Here is a look at the request XML:

    <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
    <packet version=\"1.3.2.4\">
    <client>
    <set>
    <filter>
    <id>29</id>
    </filter>
    <values>
    <limits>
    <max_webapps>5</max_webapps>
    <max_maillists>0</max_maillists>
    <max_resp>5</max_resp>
    <max_mg>5</max_mg>
    <max_redir>5</max_redir>
    <mbox_quota>5000</mbox_quota>
    <max_box>20</max_box>
    <max_db>1</max_db>
    <max_wu>0</max_wu>
    <max_traffic>20000</max_traffic>
    <disk_space>1500</disk_space>
    <max_subdom>2</max_subdom>
    <max_dom>1</max_dom>
    </limits>
    </values>
    </set>
    </client>
    </packet>

    and here is the response XML:
    <?xml version="1.0" encoding="UTF-8"?>
    <packet version="1.3.2.4">
    <client>
    <set>
    <result>
    <status>ok</status>
    <id>29</id>
    </result>
    </set>
    </client>
    </packet>

    I have tried changing the values of disk_space to multiple formats and numbers without success. Also, I have tried setting ONLY the disk_space and it doesn't work either, just sets it to 0.
     
  2. KulM

    KulM Guest

    0
     
    OK, figured it out... I assumed that the values for disk_space, etc. were the same as what was required when setting them manually through the control pannel... This is not the case, it is in bytes, not KB, MB, or anything else. Setting diskspace to 999999999 gave me 954MB according to the control pannel's limits section, which is accurate. Would be nice to document this a little better for future users.

    Also, all this may be obvious to some users, but I had a hard time finding this information. In the permissions section, when they say boolean, they mean 'true' and 'false', not 'TRUE' and not '1'. To set something to unlimited in the limits section leave the value blank.

    Also, can someone tell me if this is the proper way to create a domain name via the Plesk RPC API?

    Step 1: packet/client/add
    Step 2: packet/client/set/limits&permissions (optional)
    Step 3: packet/ip/get (if you want to dynamically find IPs)
    Step 4: packet/client/ippool_add_ip
    Step 5: packet/domain/add

    Seems a little lengthy to just add a domain name, but this seems to be the case.

    If anyone needs any example code of mine I would be more than happy to share as there are currently no examples other than the generic packet/server/get/gen_info in the documentation that I am aware of. Again, if I am incorrect and there is additional documentation on this, PLEASE let me know. I have been agonizing over automating signups through the API for some time and have come close to completion. BTW, my code is in PHP.
     
  3. benbroad

    benbroad Guest

    0
     
    Hi KuIM, I am about to embark on a project that is going to need to automate the domain creation in plesk - did you manage to get your creation script working reliably?

    Is the method you described in the previous post the right way to create a domain?

    Any advice in general would be greatly appreciated.

    B.
     
  4. KulM

    KulM Guest

    0
     
    Yes, I have that method in that order running right now. Here is a link to the code I have in operation right now. It's not complete as I had to strip out some sensitive data, but you should be able to at least get a very good idea of the structure and order of events.

    http://www.filecloud.com/files/file.php?user_file_id=37277

    Let me know if you have any other questions, I did write some other functions, so if you need any additional examples let me know and I'll try and send them to you or post them here.
     
  5. benbroad

    benbroad Guest

    0
     
    Thanks KuIM, your script will help us tremendously! We are going to go through it today so I will let you know how we get on.

    Again thanks for this!
     
  6. peter3030

    peter3030 Guest

    0
     
    Hello KuIM,

    Thanks for the script. We have tested your script, but we reseave a blank page, when we call the function create_webspace('test.com','password','username'). Have you perhaps an idea?

    We have tested an other script and this would fonctionned. But we reseave a response in xml-form. How can we have a response in an array, so that we could test the array, if the result is ok and then redirect on an another page?

    With regards
    Peter

    <?php

    define("HOST", "example.host.com");
    define("PORT", 8443);
    define("PATH", "enterprise/control/agent.php");
    define("LOGIN", "admin");
    define("PASSWD", "examplepass");
    define("PROTO_VER", "1.3.1.0");

    $proto = PROTO_VER;
    $data =<<<EOF
    <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
    <packet version="$proto">
    <mail>
    <create>
    <filter>
    <domain_id>1</domain_id> // You need to know your domain id number you can find this in the domains table i beleave
    <mailname>
    <name>username</name>
    <password>password</password>
    <mailbox><enabled>true</enabled></mailbox>
    </mailname>
    </filter>
    </create>
    </mail>
    </packet>
    EOF;

    function write_callback($ch, $data)
    {
    echo $data;
    return strlen($data);
    }

    function sendCommand()
    {
    $url = "https://" . HOST . ":" . PORT . "/" . PATH;

    $headers = array(
    "HTTP_AUTH_LOGIN: " . LOGIN,
    "HTTP_AUTH_PASSWD: " . PASSWD,
    "HTTP_PRETTY_PRINT: TRUE",
    "Content-Type: text/xml",
    );

    // Initalize the curl engine
    $ch = curl_init();

    // Set the curl options
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    // this line makes it work under https
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_HTTPHEADER, &$headers);

    // Set the URL to be processed
    curl_setopt($ch, CURLOPT_URL, $url);

    // Set the callback functions
    curl_setopt($ch, CURLOPT_WRITEFUNCTION, write_callback);

    // Set the data to be send
    global $data;
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

    // Debug, however...
    curl_setopt($ch, CURLOPT_VERBOSE, 1);

    $result = curl_exec($ch);

    if ($result == CURL_OK) {
    //print_r(curl_getinfo($ch));
    } else {
    echo "\n\n-------------------------\n" .
    "cURL error number:" .
    curl_errno($ch);
    echo "\n\ncURL error:" . curl_error($ch);
    }

    curl_close($ch);

    return;
    }

    sendCommand();

    ?>
     
  7. benbroad

    benbroad Guest

    0
     
    I have had some success with the API - we can now create domains on the fly which is fantastic. The problem I am having is that I can't seem to see how to add email accounts using the API, am I missing something or is this something I can't do this way?

    KuIM -> Thanks for you script, its a strpped down version of yours we are now using, saved us days of development work!

    If anyone wants a copy of it give me a yell (it just creates standard forwarding domains on a specified ip address).

    B.
     
  8. KulM

    KulM Guest

    0
     
    No, you're not missing anything unless SW-Soft has updated the API without updating the docs. As far as I could tell there is no way to do anything but manage domains and a couple other misc things through the Plesk-API. I ended up writing my own XML-RPC server/client that interacts with the Plesk-CLI. The Plesk-CLI does everything, I can create DB's, email accounts, almost anything you can do from the control pannel. This is not the best way to go and I'm not sure I can share anything helpful, as most of it is proprietary code owned by my company.

    Hopefully SW-Soft reads this and prioritizes their API a bit higher. This was one of the main features that drew me to Plesk, and I was sorely disappointed when I realized how limited the API really is.
     
  9. benbroad

    benbroad Guest

    0
     
    Yeah, we came to the same conclusion. We discovered the mail.sh command line interface that allows us to add/edit/remove email accounts so we are writing a wrapper for this at the mo - like you say, not ideal.

    As an aside, do you know if the API can be used to find the domain ID for a given domain name? at the minute we just get ALL the domains on the sever then step through the XML but its a bit of a chore....
     
  10. KulM

    KulM Guest

    0
     
    That's what I do; a big 'ole regex. Not very fun or reliable.
     
  11. benbroad

    benbroad Guest

    0
     
    I have hit a stumbling block... We can get the mail.sh script to work but only if we run it from the command line; not if we do an exec() from php (safe-mode is off).

    Did you run yours direct from php KuIM or do you do it through a wrapper? What user group do you use to run the thing?
     
  12. KulM

    KulM Guest

    0
     
    I used sudo to run it:

    # cat /etc/sudoers

    # Cmnd alias specification
    Cmnd_Alias DATABASE=/usr/local/psa/bin/database.sh

    # Defaults specification
    Defaults ignore_dot
    Defaults root_sudo

    # User privilege specification
    root ALL=(ALL) ALL
    username SERVERS=NOPASSWD: DATABASE


    ########################
    ###username is the username my web server runs as that is making the call.###

    I then run my command like so:
    $dbCreate_Call = '/usr/bin/sudo /usr/local/psa/bin/database.sh -c "'.$params[0]['id'].'" -domain "'.$params[0]['domain'].'" -add_user "'.$params[0]['id'].'" -passwd "'.$params[0]['dbPass'].'" -passwd_type "plain" -type "mysql" 2>&1';

    exec($dbCreate_Call,$resultString);
     
  13. lonnie

    lonnie Guest

    0
     
    HEY THERE :)

    Any ideas on how to create a domain based on a template? I just downloaded your zip and I intend to look through it, but I've not found anyone who's pulled this off yet.. so any ideas would be helpful.

    Thanks!

     
  14. MauriceW

    MauriceW Guest

    0
     
    Hi KulM,

    Fantastic code! Compliments!!!
    I still have one question.
    When I create a domain I allow Webstats. But how do I enable the Password protected folder '/plesk-stat/' tickbox?

    <hosting>
    <vrt_hst>
    ...
    <webstat>$global_webspace_domain_limits[webstat_enabled]</webstat>
    ...
    </vrt_hst>
    </hosting>

    Any idea?

    Kind regards,

    MauriceW
     
  15. Roosta21

    Roosta21 Guest

    0
     
    Hi thanks for files on the API,

    I have the same problem as peter3030, (with Kuim files)it just returns a blank screen, did anyone find a solution?
     
Loading...