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;
  }

}

Link to comment
Share on other sites

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.