Jump to content

Recommended Posts

I have this wonderful php class that used to let me login into cpanel and call any path I wanted. Now its broken:

<?php
class cPanel {
  var $cPanelUser   = "";
  var $cPanelPass   = "";
  var $cPanelDomain = "";
  var $cPanelPort   = 0;
  var $cPanelRel    = "";
  var $cPanelRoot   = "";

  function cPanel($cPanelDomain, $cPanelPort, $authUser, $authPass) {
    $this->cPanelDomain = $cPanelDomain;
    $this->cPanelPort = $cPanelPort;
    $this->cPanelUser = $authUser;
    $this->cPanelPass = $authPass;
    //Root path of cPanel to load pages begining with /

    $this->cPanelRoot = "http".($this->cPanelPort==2083 ? "s" : "")."://".$this->cPanelDomain.":".$this->cPanelPort."/frontend/x3/";
    //Relative path of cPanel to load pages not begining with /
    $this->cPanelRel = $this->cPanelRoot."";
  }
  function fetchPage($cPanelPage, $sPostVars = "") {
    $curl = curl_init();
    $loginf = sprintf("%s:%s", $this->cPanelUser, $this->cPanelPass);

    //Build the path. If it begins with / we go and paste at root
    if ($cPanelPage[0] == '/') {
      $url = $this->cPanelRoot.substr($cPanelPage, 1);
    }
    else {
      //Build the path - if begins with / we go and paste relative
      $url = $this->cPanelRel.$cPanelPage;
    }

    curl_setopt ($curl, CURLOPT_URL, $url."?".$sPostVars);
    curl_setopt ($curl, CURLOPT_TIMEOUT, 30);
    curl_setopt ($curl, CURLOPT_USERAGENT, sprintf("Mozilla/%d.0",rand(4,5)));
    curl_setopt ($curl, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt ($curl, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt ($curl, CURLOPT_FAILONERROR, 0);
    curl_setopt ($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
    curl_setopt ($curl, CURLOPT_USERPWD, $loginf);
    $html = curl_exec ($curl);
    echo 'Errors: ' . curl_errno($curl) . ' ' . curl_error($curl) . '<br><br>';
    echo $html;
    curl_close ($curl);

    //print_r($url);
    return $html;
  }

}

 

I am using this script on one server and calling trying to login on another server and run a fastastico script. This is the error output: Errors: 7 couldn't connect to host

 

I've checked the username and password multiple times.

 

Any ideas why this wouldn't work?

Link to comment
https://forums.phpfreaks.com/topic/240146-curl-is-not-logging-into-cpanel/
Share on other sites

The provider may have changed the server setup to not allow remote connections to cpanel, or are blocking your server from connecting, or with one client I have, with their server provider, if my ip adresss has changed, I have to email them to add the IP to the firewall otherwise I can't connect to WHM.

 

Or maybe they changed cpanel so you need to login differently. For example, they don't have the /frontend/x3/ template anymore.

 

Or there may be an issue with a router in between and you are being rerouted and it taking longer than 30 secs to connect.

 

Do a traceroute between servers.

 

If the traceroute looks good, then connect via ssh to your server then try connecting to the other server and see if you can login on that port.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.