Jump to content

Provisioing Module with curl


Rick_F

Recommended Posts

Hello,

I am trying to develop a provisioning module for WHMCS. I am using curl in order to communicate with a remote API. 

I am currently using this code

function provisioningmodule_create_login(array $params)
{
    try {
        require('login_module.php');
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_COOKIEJAR, tempnam('/tmp', 'CURLCOOKIE'));

        $responseLogin = login($curl);
        $responseCreateDomain = createDomain($curl, 'test.com', 2048, 1);
        curl_close($curl);
    } catch (Exception $e) {
        // Record the error in WHMCS's module log.
        logModuleCall(
            'provisioningmodule',
            __FUNCTION__,
            $params,
            $e->getMessage(),
            $e->getTraceAsString()
        );

        return $e->getMessage();
    }

    return 'success';
}
File login_module.php

  function login($curl)
    {
        global $url;
        global $pass;
        global $user;

        curl_setopt($curl, CURLOPT_URL, $url . '/login');
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($curl, CURLOPT_POST, TRUE);
    
        curl_setopt($curl, CURLOPT_POSTFIELDS, array(
            'username' => $user,
            'password' => $pass,
        ));

        curl_setopt($curl, CURLOPT_VERBOSE, true);
        $errStream = fopen('php://temp', 'w+');
        curl_setopt($curl, CURLOPT_STDERR, $errStream);

        $response = curl_exec($curl);

        rewind($errStream);
        $verboseLog = stream_get_contents($errStream);

        logModuleCall(
            'provisioningmodule',
            'login_raw',
            $verboseLog,
            'test',
            'test'
        );

        $responseJSON = json_decode($response, TRUE);
        return $responseJSON;
    };

Curl is not working. It even doesn't create a cookie in /tmp

But my main issue is logging. I only get the last line of the curl output in the module log which is "* Closing connection -1". What am I doing wrong? PHP doesn't error anything. Already tried setting error_log path (which is visible in the whmcs php info).

Has anyone had this problem?

Link to comment
Share on other sites

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.   Paste as plain text instead

  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

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated