The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Remote cPanel API calls via XMLAPI to access SpamAssassin

Discussion in 'cPanel Developers' started by Kevin Hands, May 3, 2015.

  1. Kevin Hands

    Kevin Hands Registered

    Joined:
    May 3, 2015
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Wiltshire, England
    cPanel Access Level:
    Reseller Owner
    I am trying to create my own frontend to the SpamAssassin module on the cPanel. I want to be able to adjust the blacklist and whitelist, the score to mark an email as spam, and the option to delete the spam. I can see the functions in API1 but not in API2 or UAPI. This is the code so far -

    Code:
    <?php 
    /**
    *
    * Adjust SpamAssasin White list and Black list
    *
    **/
    include(ABSPATH . "PHP/xmlapi.php");
    
    $domain_username = "top secret";
    $domain_password = "top secret";
    
    $ip = "top secret";
    
    $xmlapi = new xmlapi($ip);
    $xmlapi->password_auth($domain_username,$domain_password); // logon to the API
    $xmlapi->set_debug(0);
    
    // Request the SpamAssassin config from
    // the API1 functions (API1 call to SpamAssassin::config)
    $result = $xmlapi->api1_query($domain_username, "SpamAssassin", "config", array(domain=>$domain) );  
    
    // PROCESS THE $result HTML data
    
    // Request the Email Spam setting from
    // the API1 functions (API1 call to Email::has_spam_autodelete)
    $result = $xmlapi->api1_query($domain_username, "Email", "has_spam_autodelete", array(domain=>$domain) );
    
    // NOW READ THE spam_auto_delete AND spam_auto_delete_score CPANEL VARIABLES
    ?>
    
    
    This gives me the white list and black list after some PHP processing.
    But I can't see how to get the CPANEL VARIABLES into a PHP variable.

    Thanks for any help
     
    #1 Kevin Hands, May 3, 2015
    Last edited by a moderator: May 3, 2015
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,683
    Likes Received:
    654
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    Hello,

    You may receive more user-feedback on this type a question a forum more suited to PHP development questions. The forum here is primarily intended for discussions about the cPanel API itself (e.g. how to obtain the data). Note that you may want to submit a feature request for the additional SpamAssassin functions for cPanel API2/UAPI:

    Submit A Feature Request

    Thank you.
     
  3. Kevin Hands

    Kevin Hands Registered

    Joined:
    May 3, 2015
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Wiltshire, England
    cPanel Access Level:
    Reseller Owner
    I have managed to get the code working so that I can now read the SpamAssassin configuration. But I can't save the information back with the "SpamAsssain-saveconfig" API call. I pass the paremeters that it requires but all that happens is it reurns OK and the configuration in SpamAssassin is reset i.e. the black list and white lists are cleared and the score is set to 5. The parameters I am passing are-
    blacklist_from1-user@example.com
    6
    Spam_Rule 3 3 3
    whitelist_from1-test@test.co.uk
    I am using curl to test the api. The curl data for the failing spamassassin api reads -"cpanel_xmlapi_user=test&cpanel_xmlapi_module=SpamAssassin&cpanel_xmlapi_func=saveconfig&cpanel_xmlapi_apiversion=1&arg-0=blacklist_from1-user@example.com&arg-1=6&arg-2=SPAM_RULE 3 3 3&arg-3=whitelist_from1-test@test.co.uk"

    I have tested my curl commands and I can successfully add an email account with the API function "Email-addpop" and parameters-
    user
    12345luggage!
    500
    test.com
    NOTE - the domain name test.com is repacing my actual domain

    Thanks in advance
     
  4. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,683
    Likes Received:
    654
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    It's important to keep in mind that cPanel API 1 is deprecated. There's actually an internal case open to address the issue with the reset of the user_prefs file when new configuration values are added through the API (case number 48867). However, it's not likely this case will be addressed due to the deprecation of cPanel API 1. It's likely better to develop a custom script that directly modifies the configuration files, or to open a feature request for SpamAssassin API functionality.

    Thank you.
     
Loading...

Share This Page