Dec 15, 2016
6
0
1
india
cPanel Access Level
Website Owner
I want a script to logged in to cpanel using username and password with thehelp of curl. this is what I am currently using

Code:
function createSession() { // Example details
$ip = "127.0.0.1";
$cp_user = "username";
$cp_pwd = "password";
$url = "http://$ip:2082/login";
$cookies = "/path/to/storage/for/cookies.txt";

// Create new curl handle
$ch=curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookies); // Save cookies to
curl_setopt($ch, CURLOPT_POSTFIELDS, "user=$cp_user&pass=$cp_pwd");
curl_setopt($ch, CURLOPT_TIMEOUT, 100020);

// Execute the curl handle and fetch info then close streams.
$f = curl_exec($ch);
$h = curl_getinfo($ch);
curl_close($ch);

// If we had no issues then try to fetch the cpsess
if ($f == true and strpos($h['url'],"cpsess"))
{
    // Get the cpsess part of the url
    $pattern="/.*?(\/cpsess.*?)\/.*?/is";
    $preg_res=preg_match($pattern,$h['url'],$cpsess);
}

// If we have a session then return it otherwise return empty string
return (isset($cpsess[1])) ? $cpsess[1] : "";
}
 
Last edited by a moderator:
Dec 15, 2016
6
0
1
india
cPanel Access Level
Website Owner
Hi

Thanks for the fast reply

use lib '/usr/local/cpanel';

How I can get this?
Can you give me this liberary?
I am being able to get logged in to my cpanel account. but not possible to third person account who come on my site to take backup


Thanks
 
Dec 15, 2016
6
0
1
india
cPanel Access Level
Website Owner
132.148.xx.xxx:2083/cpsess3979807116/login/?session=pickupherew%3ahGFZD6Y3FxEejN25%3acreate_user_session%2c874804442c9944d3129301bf484a57bce

I get a sessionurl some thing like this when I open this url in the browser it get me logged in straight away. but when I am hitting this with curl it doing nothing giving error like this

[16-Dec-2016 07:38:10 Etc/GMT] curl_exec111 threw error "Failed to connect to 132.148.xx.xxx port 2083: Connection timed out" for 132.148.xx.xxx:2083/cpsess3979807116/login/?session=pickupherew%3ahGFZD6Y3FxEejN25%3acreate_user_session%2c87480444d2c9944d3129301bf484a57bce
 
Last edited by a moderator:

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,904
2,218
463
Hello,

Could you provide some more information about the exact steps you are taking, and what your custom script looks like? For instance, which example are you following from the URL in my last response? Please provide as much information as possible to help us reproduce the issue.

Thank you.
 
Dec 15, 2016
6
0
1
india
cPanel Access Level
Website Owner
I am trying every possible solution to get the result. But all in vain.

I am trying a third party login into the cpanel. I just need a script to login in to the third party server and takes backup.
Like I am on server 208.91.xxx.xx and I want to login and take a backup of the 132.148.xx.xxx . Is that possible to do ?
the you can give me definite solution please

Login in to the Cpanel is not my concern. The main concern is to get backup of any email account with cpanel details.
I am using cpanel xmlapi 1 to get the backup. I am able to get backup of my server on which my code is hosted but not able to get the backup of any other backup.

can you available to chat India Time 9.30 to 6.30. So that I can get to a conclusion weather it is possible or not to take any backup


Thanks
 
Last edited by a moderator:

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,904
2,218
463
I am able to get backup of my server on which my code is hosted but not able to get the backup of any other backup.
Do you have cPanel login credentials to the remote server, and if so, do backup options work manually via the cPanel UI on that server? This is required if you want to setup a script to run a cPanel API 1 backup functions on a remote server.

Thank you.
 
Dec 15, 2016
6
0
1
india
cPanel Access Level
Website Owner
hi

Every time I created a new crontab in the cron jobs a new linkey (unique ID ) is added to the current cron queue. How I can stop that ?
It is also updated every time I updated a cron job earlier set by me

Thanks

<code>
return $xmlapi->api2_query($account, "Cron", "edit_line", array(
"linekey" => $line_key,
"command"=>$command,
"day"=>$day,
"hour"=>$hour,
"minute"=>$minute,
"month"=>$month,
"weekday"=>$weekday
));
</code>
<code>
return $xmlapi->api2_query($account, "Cron", "add_line", array(
"command"=>$command,
"day"=>$day,
"hour"=>$hour,
"minute"=>$minute,
"month"=>$month,
"weekday"=>$weekday
));die;
</code>
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,904
2,218
463
Every time I created a new crontab in the cron jobs a new linkey (unique ID ) is added to the current cron queue. How I can stop that ?
It is also updated every time I updated a cron job earlier set by me
Could you let us know the step-by-step instructions we can take to reproduce this issue? Please include details about the specific cron job and commands you are using.

Thank you.