Jump to content

API from any IP


Niklas

Recommended Posts

Hello,

 

I made a small piece of code that i think could help out others with a similar issue.

I have about hundred servers that is sending welcome emails out themself instead of having WHMCS to do it. That was annoying since i couldn't resend old emails, so i decided to use the WHMCS API to send emails. But i quickly ran into an issue - i had to add every single server IP on the API allow list. As i couldn't find an option to disable this allow list, i had to figure something else out. I ended up with writing a small PHP script that acts as a proxy to the API, so i only would have to whitelist the IP of the webserver. Simply copy/paste the following code into whmcs/includes/localapi.php (actually localapi.php can be called anything), and then use that file instead of api.php:

 

<?php

$ch = curl_init();

$url = str_replace('/'.basename(__FILE__),'/api.php',$_SERVER['REQUEST_URI']);

if (isset($_SERVER['HTTPS'])&&$_SERVER['HTTPS']=='on') {
   curl_setopt($ch, CURLOPT_URL, 'https://'.$_SERVER['HTTP_HOST'].$url);
   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
} else {
   curl_setopt($ch, CURLOPT_URL, 'http://'.$_SERVER['HTTP_HOST'].$url);
}

if (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST') {
   curl_setopt($ch, CURLOPT_POST, true);
   curl_setopt($ch, CURLOPT_POSTFIELDS, $_POST);
}

curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);

// Lighttpd doesn't support the Expect header.
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));

curl_exec($ch);

?>

 

Best regards,

Niklas

Link to comment
Share on other sites

  • 9 years later...

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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • 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