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.

Loop through all accounts and run api calls?

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

  1. MACscr

    MACscr Well-Known Member

    Joined:
    Sep 30, 2003
    Messages:
    190
    Likes Received:
    1
    Trophy Points:
    18
    cPanel Access Level:
    Root Administrator
    I am making two different scripts, one that runs a cpanel plugin and is obviously limited to the current user. The other script just runs from a cron job as root, but I am not sure how you specify what cpanel account i want it to fetch the data for. If I am doing something like so:

    PHP:
    $r $cpanel->api2('Email''listdomainforwards');
    var_dump($r);
    Is there a way for me to specify the cpanel account as well? I think there might be a way to do all of this using the xmlapi, but I would rather not and since this is running internally, there is no reason to do any type of authentication. Am I missing something?
     
  2. KostonConsulting

    KostonConsulting Well-Known Member

    Joined:
    Jun 17, 2010
    Messages:
    255
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    San Francisco, CA
    cPanel Access Level:
    Root Administrator
    What are you using to connect to cPanel if you're not using the cPanel XML API PHP class? Where is the $cpanel->api2() function defined?

    In the cPanel XML API PHP class, you call API2 like so and can set the user:

    Code:
    api2_query($user, $module, $function, $args = array())
    
    The only way I'm aware of not using auth credentials as root is to load up Cpanel::XML in Perl like so:

    Code:
    #!/usr/bin/perl
    BEGIN{ unshift(@INC,'/usr/local/cpanel'); }
    use Cpanel::XML ();
    use Data::Dumper ();
    use XML::Simple ();
    
    my $args = {
            'cpanel_xmlapi_module' => 'Email',
            'cpanel_xmlapi_func' => 'listdomainforwards',
            'cpanel_xmlapi_apiversion' => '2',
            'cpanel_xmlapi_user' => $user
        };
    my $xml = Cpanel::XML::cpanel_exec_fast( $args );
    my $xmlRef = XML::Simple::XMLin($xml);
    print Data::Dumper::Dumper($xmlRef);
    
    

    You can 'ls /var/cpanel/users' to get a list of all the cPanel users.
     
  3. MACscr

    MACscr Well-Known Member

    Joined:
    Sep 30, 2003
    Messages:
    190
    Likes Received:
    1
    Trophy Points:
    18
    cPanel Access Level:
    Root Administrator
    I am actually using the LiveAPI LiveAPI — PHP. My perl skills are pretty much nil, so I am using php or bash for simple stuff.
     
  4. KostonConsulting

    KostonConsulting Well-Known Member

    Joined:
    Jun 17, 2010
    Messages:
    255
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    San Francisco, CA
    cPanel Access Level:
    Root Administrator
    LiveAPI can only run within the cPanel web server (cpsrvd). You can't run it from the command line as root as the permissions to access the cPanel account are built into cPanel's web server (running on ports 2083 and 2087). If you are running something from the command line, you are no longer in cPanel so you'll need to connect to cPanel via API which means using the XMLAPI to connect.
     
Loading...

Share This Page