Jump to content

does anybody know how to connect to cpanel with curl?


ballhogjoni

Recommended Posts

I found this class online that looks like it should work. I have googled quite a bit on how to get this to work, but I can't find anything. All the discussions on google are a couple years old.

 

<?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."/";
    //Relative path of cPanel to load pages not begining with /
    $this->cPanelRel = $this->cPanelRoot."";
  }

  function fetchPage($cPanelPage, $sPostVars = "") {
    $ch = 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 ($ch, CURLOPT_URL, $url);
    curl_setopt ($ch, CURLOPT_POST, true);
    curl_setopt ($ch, CURLOPT_POSTFIELDS, $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 ($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
//    curl_setopt ($curl, CURLOPT_SSL_VERIFYHOST, 0);
//    curl_setopt ($curl, CURLOPT_FAILONERROR, 0);
    echo $loginf;
    echo $url."?".$sPostVars;
    curl_setopt ($ch, CURLOPT_USERPWD, $loginf);
    curl_setopt ($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
    $result = curl_exec ($ch);
    echo 'Errors: ' . curl_errno($ch) . ' ' . curl_error($ch) . '<br><br>';
    
    curl_close ($ch);

    return $result;
  }

}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.