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.

Custom Anti-Spam plugin planning

Discussion in 'cPanel Developers' started by MACscr, Oct 16, 2013.

  1. MACscr

    MACscr Well-Known Member

    Joined:
    Sep 30, 2003
    Messages:
    190
    Likes Received:
    1
    Trophy Points:
    18
    cPanel Access Level:
    Root Administrator
    OK, so I am creating a plugin for internal use that will be used by cpanel users to create their email whitelists and also set a minimum score for spam. I used the cpanel plugin generator to create the basic installer for the icon, etc, but I am not sure about how to then actually handle the creation of the actual contents of the plugin. The installer doesnt really mention anything about that. So if I am using the live API, how am I supposed to automate the creation of x3/mypluginname/branded.live.php, etc?

    Secondly, I am storing these settings encoded in a JSON structure and stored in a text file in the users home directory. I then have a script that runs as root and pretty much creates a master json object that includes all the users settings. Now, I am not sure what the best method is for allowing that json data to be available externally to my anti-spam gateways. Id really rather pull it from the gateway instead of push it to it. Any suggestions on the simplest method? Id rather not go through the pain of having to setup ssh accounts and scp the data. I can create a simple api that I could access through curl and simply use a hash for auth and ssl, but where should i make it accessible? Should I just use the servers hostname and use its normal /usr/local/apache/htdocs?

    I am open to suggestions and I really appreciate your help brainstorming this. I am sure I am overcomplicating the process, so figured another view on this would help.
     
  2. cPAndrewHodge

    cPAndrewHodge cPanel UI Developer
    Staff Member

    Joined:
    Dec 10, 2012
    Messages:
    52
    Likes Received:
    3
    Trophy Points:
    8
    cPanel Access Level:
    Root Administrator
    What you can do (and this is what I had originally done when I worked on the x4 installer) is this:

    Create an install script with Perl
    From the install script call register_plugin similar to this:
    Code:
    sub register_x4_plugin {
        if ( -x "/usr/local/cpanel/bin/register_cpanelplugin" ) {
            print "\nRegistering plugin with cPanel...\n";
            `/usr/local/cpanel/bin/register_cpanelplugin x4.cpanelplugin`; #Replace this with your .cpanelplugin file
        }
        else {
            print "\nFailed to register plugin with cPanel\n";
        }
    }
    
    If your plugin registers, copy files over
    ...and you're done!

    Now you should also have an uninstall script, since that's the best practice. For that....

    Write a Perl script
    From there call unregister_plugin (make sure to specify your plugin)
    Code:
    sub unregister_x4_plugin {
        if ( -x "/usr/local/cpanel/bin/unregister_cpanelplugin" ) {
            print "Unregister plugin with cPanel...\n";
            `/usr/local/cpanel/bin/unregister_cpanelplugin /var/cpanel/registered_cpanelplugins/x4theme`;
        }
        else {
            print "Failed to unregister plugin with cPanel.\n";
        }
    }
    
    Remove files as needed

    ..and that's it!


    edit: Oh! To install just run from the command line.

    edit2: Docs link! http://docs.cpanel.net/twiki/bin/view/SoftwareDevelopmentKit/WritingcPanelPlugins
     
  3. MACscr

    MACscr Well-Known Member

    Joined:
    Sep 30, 2003
    Messages:
    190
    Likes Received:
    1
    Trophy Points:
    18
    cPanel Access Level:
    Root Administrator
    Where should i be storing my plugin? /usr/local/cpanel/3rdparty/ just doesnt seem right.

    Also, what method should I use to automatically make my plugin available for all cpanel themes?

    Important note, I am only using php and a little bash. I don't know perl and won't be using it.
     
Loading...

Share This Page