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

[API] Using API for creating mailboxes

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

  1. Flyer@

    Flyer@ Guest

    0
     
    Ok, I have an own server running Plesk 7.5 Reloaded.

    To begin: I have some "big" websites that I run. And one of that big website we are going to upgrade building an webmail application to it. To use that webmail, people first use to sign up before they can use it.

    Then, looking hard on this website, I found a solution: Shell scripts. But, a little problem, I don't have the user-rights to access them. And because I don't have the root password I can't change anything of that..

    So I look further on the website and I called the people who are controlling my server. And I get an other option: Using API. I don't know API but it must work with API. So I have search on plesk and I have search google for finding some information about plesk & api. I didn't find anything. The only thing I found was an dead link linking to an doc here on plesk that maybe could help me.

    So my guestion is, How can I write an script in PHP that will be able create mailboxes? If it is possible with API, where can I find the doc's of this API so I know what to do.
     
  2. Flyer@

    Flyer@ Guest

    0
     
  3. Flyer@

    Flyer@ Guest

    0
     
    Please some??? I need this. It is very inportant.

    I need to build an php-script than can create mail-accounts. And I can't use the the shell scripts only the API scripts. So please if someone has an answer for me.. I will thank you forever. Also if needed I will pay for it...
     
  4. ZeroPain

    ZeroPain Guest

    0
     
    I would also like to know this.
     
  5. 0031

    0031 Guest

    0
     
    Plesk 7.5.3 adds support for mailname operations through API RPC. They didn't update SDK about it, so the only source of information available is schemas from psa-api-rpc-protocol package. Generally it should be the same as with other packet types (clients/domains).

    The bad thing about this schemas - you'll need XMLSpy to read them easily..
     
  6. Jason Lee

    Jason Lee Guest

    0
     
    Hi,

    Did you manage to figure out how to create mailboxes using the API ? If so could you provide an example of the XML you used to create the accounts?

    Thanks in advance,
     
  7. ZeroPain

    ZeroPain Guest

    0
     
    I found a way to do it but you have to be fully updated to the newest build. i can't remember the excate version number but i'll post a small example using php.

    PHP:

    <?php

    define
    ("HOST""pleskhostname");
    define("PORT"8443);
    define("PATH""enterprise/control/agent.php");
    define("LOGIN""admin");
    define("PASSWD""admin-password");
    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>4</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>1</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($chCURLOPT_SSL_VERIFYHOST0);
            
    // this line makes it work under https
            
    curl_setopt($chCURLOPT_SSL_VERIFYPEERFALSE);
            
    curl_setopt($chCURLOPT_HTTPHEADER, &$headers);

            
    // Set the URL to be processed
            
    curl_setopt($chCURLOPT_URL$url);

            
    // Set the callback functions
            
    curl_setopt($chCURLOPT_WRITEFUNCTIONwrite_callback);

            
    // Set the data to be send
            
    global $data;
            
    curl_setopt($chCURLOPT_POSTFIELDS$data);

            
    // Debug, however...
            
    curl_setopt($chCURLOPT_VERBOSE1);

            
    $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();

    ?>

    I can't say this is the best way to do it or not. i'm not a super php guru but it did work for me :)

    I did use xmlspy to find all the info for it. there are a few more options thinking about making a simple little configurable script to release with all the options displayed so others can use it. if there is any interest i may do it
     
  8. Jason Lee

    Jason Lee Guest

    0
     
    Thanks, that worked. Is it possible to enable spam filtering using the API ?
     
  9. ZeroPain

    ZeroPain Guest

    0
     
    i honestly can't remember i'll have to remember where i got all the info to make that
     
  10. ZeroPain

    ZeroPain Guest

    0
     
    Sorry i'm not seeing a spam option of any kind but i could be missing it somewhere.

    if you have updated to the newest version just grab a copy of the
    xsd files and open them with xmlspy or something like it.

    /usr/local/psa/admin/plib/api-rpc/protocol/

    they are all in that folder if i remember right.
    it took me a bit to get the hang of understanding it but its easy enough once you get it.
     
  11. Jason Lee

    Jason Lee Guest

    0
     
    I took a look through that file and it doesn't apear to be possible to enable spam filtering via the API.
     
  12. Jason Lee

    Jason Lee Guest

    0
     
    Have any of you used the API for updating mail accounts? For example changing the password of a mail account? I'm still trying to comprehend this XML API and any help would be apreciated.
     
  13. ZeroPain

    ZeroPain Guest

    0
     
    I beleave you just change create to edit but i don't have a copy of teh api xml near me. to look for sure.
     
  14. Jason Lee

    Jason Lee Guest

    0
     
    Tried changing it to update like it said in the file but that didn't work.
     
  15. bartje3

    bartje3 Guest

    0
     
    Hi,

    Maybe use "set" ?

    Bart
     
  16. 0031

    0031 Guest

    0
     
    Try this xml (mailname with mailbox):

    <packet version="1.3.4.1">
    <mail>
    <create>
    <filter>
    <domain_id>DOMAIN_ID_HERE</domain_id>
    <mailname>
    <name>some_mailname</name>
    <mailbox>
    <enabled>true</enabled>
    </mailbox>
    <password>SOMEPASSWORD</password>
    </mailname>
    </filter>
    </create>
    </mail>
    </packet>

    It's described in plesk_mailname.xsd and mailname_input.xsd shiped in psa-api-rpc-doc package...
     
  17. peter3030

    peter3030 Guest

    0
     
    Hello

    This script works also for me. Have somebody an idea how we can integrate this in an application, in the way, that we have the result in a array and not in xml?

    With regards
    Peter


    PHP:

    <?php

    define
    ("HOST""pleskhostname");
    define("PORT"8443);
    define("PATH""enterprise/control/agent.php");
    define("LOGIN""admin");
    define("PASSWD""admin-password");
    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>4</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>1</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($chCURLOPT_SSL_VERIFYHOST0);
            
    // this line makes it work under https
            
    curl_setopt($chCURLOPT_SSL_VERIFYPEERFALSE);
            
    curl_setopt($chCURLOPT_HTTPHEADER, &$headers);

            
    // Set the URL to be processed
            
    curl_setopt($chCURLOPT_URL$url);

            
    // Set the callback functions
            
    curl_setopt($chCURLOPT_WRITEFUNCTIONwrite_callback);

            
    // Set the data to be send
            
    global $data;
            
    curl_setopt($chCURLOPT_POSTFIELDS$data);

            
    // Debug, however...
            
    curl_setopt($chCURLOPT_VERBOSE1);

            
    $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();

    ?>

     
  18. 0031

    0031 Guest

    0
     
    Do you want to have result of mailname creation in array form, or do you have parameters of mailname creation as an array?

    Anyway you'll need a xml parser, to make an array <-> xml conversion. You may search on pear.php.net or write it itself, using DOM or PHP5's SimpleXML extension (very simple actually).
     
  19. peter3030

    peter3030 Guest

    0
     
    Hello

    We have found the following convert-function, but i don't know, how to implented in the script.

    With regards
    Peter

    function XMLtoARRAY($rawxml) {
    $xml_parser = xml_parser_create();
    xml_parse_into_struct($xml_parser, $rawxml, $vals, $index);
    xml_parser_free($xml_parser);

    $params = array();
    $level = array();
    foreach ($vals as $xml_elem) {
    if ($xml_elem['type'] == 'open') {
    $level[$xml_elem['level']] = $xml_elem['tag'];
    }
    if ($xml_elem['type'] == 'complete') {
    $start_level = 1;
    $php_stmt = '$params';
    while($start_level < $xml_elem['level']) {
    $php_stmt .= '[$level['.$start_level.']]';
    $start_level++;
    }
    $php_stmt .= '[$xml_elem[\'tag\']] = $xml_elem[\'value\'];';
    eval($php_stmt);
    }
    }
    return($params);
    }
     
  20. poldo76

    poldo76 Guest

    0
     
    don't work :confused:
    you have a script that works?
     
Loading...