The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Execute Files Using Access Hash For Custom Billing Script

Discussion in 'General Discussion' started by dkz, May 5, 2005.

  1. dkz

    dkz Well-Known Member

    Joined:
    Sep 10, 2004
    Messages:
    100
    Likes Received:
    0
    Trophy Points:
    16
    Hello,

    I'm working a custom account setup/billing API for cPanel and making progress but I am a little stuck. I need to execute a php file in the /scripts(custom script) directory from a web page using the access hash but I can't get it to work. Here is the current script. I used a simular script to create accunts using the whmreq function that I got from accounting.php.inc.

    PHP:
    #!/usr/local/cpanel/3rdparty/bin/php

    <?

    $host = "localhost";
    $user = "root";
    $accesshash = 
    "Hash Goes Here";

    //WHMREQ Function
    global $cpanelaccterr;
    function whmreq ($request,$host,$user,$accesshash,$usessl) {

        $cleanaccesshash = preg_replace("'(\r|\n)'","",$accesshash);
            $authstr = $user . ":" . $cleanaccesshash;
        $cpanelaccterr = "";


        if (function_exists("curl_init")) {
            $ch = curl_init();
            if ($usessl) {
                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);                
                curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,0);
                curl_setopt($ch, CURLOPT_URL, "https://${host}:2087" . $request);
            } else {
                curl_setopt($ch, CURLOPT_URL, "http://${host}:2086" . $request);
                    }
            curl_setopt($ch, CURLOPT_HEADER, 0);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
                $curlheaders[0] = "Authorization: WHM $authstr";
                    curl_setopt($ch,CURLOPT_HTTPHEADER,$curlheaders);
            $data=curl_exec ($ch);
            curl_close ($ch);
        } elseif (function_exists("socket_create")) {
            if ($usessl) {
                $cpanelaccterr = "SSL Support requires curl";
                return;
            }
            $service_port = 2086;
            $address = gethostbyname($host);
            $socket = socket_create (AF_INET, SOCK_STREAM, 0);
            if ($socket < 0) {
                    $cpanelaccterr = "socket_create() failed";
                return;
            }
            $result = socket_connect ($socket, $address, $service_port);
            if ($result < 0) {
                    $cpanelaccterr = "socket_connect() failed";
                return;
            }
            $in = "GET $request HTTP/1.0\n";
            socket_write($socket,$in,strlen($in));    
            $in = "Connection: close\n";
            socket_write($socket,$in,strlen($in));    
            $in = "Authorization: WHM $authstr\n\n\n";
            socket_write($socket,$in,strlen($in));    
        
            $inheader = 1;
            while(($buf = socket_read($socket, 512)) != false) {
              if (!$inheader) {
                  $data .= $buf;
                  }
              if(preg_match("'\r\n\r\n$'s", $buf)) {
                $inheader = 0;
              }
              if(preg_match("'\n\n$'s", $buf)) {
                $inheader = 0;
              }
              if(preg_match("'\r\n$'s", $buf)) {
                $inheader = 0;
              }
            }

        } else {
            $cpanelaccterr = "php not compiled with --enable-sockets OR curl";
            return;
        }

        return $data;    
    }
    //End WHMREQ Function

    $response = whmreq("/scripts/passwd.php",$host,$user,$accesshash,$usessl); 

    print_r($response);

    ?>
    What am I missing?
    Thanks for the help...
     
Loading...

Share This Page