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.

Hook to add addon domain.

Discussion in 'cPanel Developers' started by Augusto Will, Jan 23, 2015.

  1. Augusto Will

    Augusto Will Member

    Joined:
    Sep 9, 2011
    Messages:
    19
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    I need to run a php script when user creates an addon domain in cpanel.
    If I use Api2::AddonDomain::addaddondomain, the script is called when a user go to cpanel and creates a new addon domain? Or only if the addon is created via API?
    My manage_hooks list show this:

    Cpanel:
    Api2::AddonDomain::addaddondomain:
    stage: post
    escalateprivs: 0
    weight: 200
    id: DVq_gNCtDh8hdYV6PLtoaYjl
    exectype: script
    hook: /var/cpanel/ax/ohs.php

    But if i go to cpanel and add a new add-on, the script is not called. Why?
    How is the correct way to do that?

    Thank you.
     
  2. sparek-3

    sparek-3 Well-Known Member

    Joined:
    Aug 10, 2002
    Messages:
    1,382
    Likes Received:
    23
    Trophy Points:
    38
    cPanel Access Level:
    Root Administrator
    I'm actually interested in this too. Haven't been able to get it to work, but I'm really new to scripting hooks, so I blew it off as not knowing enough.

    It doesn't appear that anything is passed to the script in $argv when the script is run. At least that's what I found.

    I added the code:

    PHP:
    ob_start();
    print_r($argv);
    $message ob_get_contents();
    ob_end_clean();
    mail("email@address.com","Addon Hook"$message);
    at the top of the hook script, and I don't get the expected results.
     
  3. Augusto Will

    Augusto Will Member

    Joined:
    Sep 9, 2011
    Messages:
    19
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    yeah, i put an file_put_contents('/hookcont.txt', $contents); in the script, no results. :)


    sparek-3, try this:


    Code:
    function get_passed_data() {
        $raw_data;
        $stdin_fh = fopen('php://stdin', 'r');
        if ( is_resource($stdin_fh) ) {
            stream_set_blocking($stdin_fh, 0);
            while ( ($line = fgets( $stdin_fh, 1024 )) !== false ) {
                $raw_data .= trim($line);
            }
            fclose($stdin_fh);
        }
        if ($raw_data) {
            $input_data = json_decode($raw_data, true);
        } else {
            $input_data = array('context'=>array(),'data'=>array(), 'hook'=>array());
        }
    
    
        return $input_data;
    	
    }
    
    
    $input = get_passed_data();
    $contents = var_export($input, true);
    file_put_contents('/hookcont.txt',  $contents);
    mail("email@address.com","Addon Hook",  $contents);  
    
     
    #3 Augusto Will, Jan 23, 2015
    Last edited: Jan 23, 2015
  4. sparek-3

    sparek-3 Well-Known Member

    Joined:
    Aug 10, 2002
    Messages:
    1,382
    Likes Received:
    23
    Trophy Points:
    38
    cPanel Access Level:
    Root Administrator
    Wow! Thanks! That was immensely helpful. Actually solved my problem. Never occurred to me that the script was being treated as a pipe. I guess that's in the documentation some where. Thanks for giving me the heads up on that. My use was for a pre hook instead of a post hook.

    I don't guess that really helps you though.

    Have you tried setting the debughooks variable in /var/cpanel/cpanel.config and tailing the /usr/local/cpanel/logs/error_log while creating an addon domain?

    There is information on this at:

    https://documentation.cpanel.net/display/SDK/Guide+to+Standardized+Hooks+-+Debug+Mode

    Not sure if it will really help you, but that's all I've got.

    Thanks again for your help in solving my problem.
     
  5. Augusto Will

    Augusto Will Member

    Joined:
    Sep 9, 2011
    Messages:
    19
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
  6. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,762
    Likes Received:
    662
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    Hello :)

    Yes, the hookable events should apply to actions performed in the cPanel/WHM UI as well as the command line. Feel free to open a support ticket if this is not functioning as expected so we can take a closer look. You can post the ticket number here so we can update this thread with the outcome.

    Thank you.
     
Loading...

Share This Page