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 API call as root

Discussion in 'cPanel Developers' started by ruyrocha, Oct 18, 2011.

  1. ruyrocha

    ruyrocha Member

    Joined:
    Oct 12, 2010
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Brasil
    Hello team,

    I've placed Dummy module into /usr/local/cpanel/Cpanel/Dummy.pm and source has only one function other than init:

    No problem here but I cannot use root to call this API. It works when I pass a valid cPanel account:

    But doesn't work for root:

    Got an Internal Server Error and the message "Could not setuid to root at /usr/local/cpanel/Whostmgr/XMLUI/cPanel.pm line 87" after enabling debug,

    I need to restrict access to Dummy module and make some actions as root (or other specific system user). Could you please help me?
     
  2. ruyrocha

    ruyrocha Member

    Joined:
    Oct 12, 2010
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Brasil
    I've found how to restrict access in Custom Event Handler docs - Custom Event Handlers

    But how to call API as root? Is it possible?
     
  3. morissette

    morissette Well-Known Member

    Joined:
    May 24, 2009
    Messages:
    119
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Austin, TX
    cPanel Access Level:
    Root Administrator
    I use the following to do api calls as root:

    Code:
    get_accesshash();
    my $cp = Cpanel::PublicAPI->new( 'user' => 'root', 'accesshash' => my $accesshash );
    
    sub get_accesshash{
            open my $hash, "<", "/root/.accesshash";
                    my @accesshash = <$hash>;
            close $hash;
            foreach(@accesshash){
                    $accesshash .= $_
            }
    }
    
     
Loading...

Share This Page