1

Topic: Remote Failed to connect - API

==== REQUIRED BASIC INFO OF YOUR IREDMAIL SERVER ====
- iRedMail version (check /etc/iredmail-release): 1.3
- Deployed with iRedMail Easy or the downloadable installer? download
- Linux/BSD distribution name and version: CentOS
- Store mail accounts in which backend (LDAP/MySQL/PGSQL): MySQL
- Web server (Apache or Nginx): Nginx
- Manage mail accounts with iRedAdmin-Pro? Yes
- [IMPORTANT] Related original log or error message is required if you're experiencing an issue.
====

I am trying to setup some API calls from a different server.

But within php I am getting error:
Failed to connect to xxx.xxx.xxx.xxx: Permission denied
(I cannot see this error within /var/log/messages on the mail server)

If I run the same code from the mail server it works just not from any remote server.

Is "Failed to connect to xxx.xxx.xxx.xxx: Permission denied" a username and password error or a IP block error?

Any help would be appreciated.
Thank You

2

Re: Remote Failed to connect - API

mikey wrote:

But within php I am getting error:
Failed to connect to xxx.xxx.xxx.xxx: Permission denied

This seems a php or network error, not iRedAdmin-Pro access control.
If it's iRedAdmin-Pro API response, it will be a JSON string.

----

Does my reply help a little? How about buying me a cup of coffee ($5) as an encouragement?

buy me a cup of coffee

3 (edited by mikey 2020-08-18 16:49:54)

Re: Remote Failed to connect - API

ok thank you for that info.

This code works on the mail server but not on a remote server on the same network.
   

$GLOBALS['setapi'] = uniqid();
$APIUSERNAME = "xxxxxx";
$APIPASSWORD = "xxxxxx";
$post = array('username'=>$APIUSERNAME, 'password'=>$APIPASSWORD);    
$post = http_build_query($post);
$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://xxxxxx/iredadmin/api/login",
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => $post,
  CURLOPT_SSL_VERIFYHOST=>false,
  CURLOPT_SSL_VERIFYPEER=>false,
  CURLOPT_RETURNTRANSFER=>true,
  CURLOPT_COOKIEJAR=>$_SERVER['DOCUMENT_ROOT']."/cgi-bin/temp/".$GLOBALS['setapi'],
));
    
$response = curl_exec($curl); 
curl_close($curl);
echo curl_error($curl);
$jsonresponse = json_decode($response);


I made a very simple version to check the output.

$urladdress = "https://xxxxxx/iredadmin/api/login"; 
$ch = curl_init(); curl_setopt($ch, CURLOPT_URL,"$urladdress"); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_HEADER, 0); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
$result = curl_exec ($ch); 
echo $result; 
echo curl_error($ch); 
curl_close ($ch);

The expected output would be "{"_success": false, "_msg": "INVALID_HTTP_METHOD"}" but I get "Failed to connect to 35.178.233.35: Permission denied"


If I run the below code from the shell of the remote server the output in login is "{"_success": false, "_msg": "INVALID_HTTP_METHOD"}" so the server seems to be able to contact.

wget https://mx1.syntaxlink.co.uk:8080/iredadmin/api/login

So this must be a PHP connect error of some kind.

4

Re: Remote Failed to connect - API

EASY FIX!!!!!!!!!!!!!!!

$ sudo setsebool httpd_can_network_connect 1

smile