Loop through all accounts and run api calls?
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);
[/PHP]
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?
-
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: 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:#!/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.0 -
I am actually using the LiveAPI [url=http://docs.cpanel.net/twiki/bin/view/SoftwareDevelopmentKit/LivePHP]LiveAPI — PHP. My perl skills are pretty much nil, so I am using php or bash for simple stuff. 0 -
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. 0
Please sign in to leave a comment.
Comments
3 comments