PHP, IPTables, and Request to Flask

338 views Asked by At

=====

UPDATE

I am having a degree of success connecting to the server with fsockopen. However, I would like to use cUrl if possible.

=====

Original

I am trying to make a request to flask using curl in the form of a post. The goal is not to use jQuery but to achieve more separation and validation of information. Despite being able to make a request from my desktop, I cannot make a request from my web server. I have iptables running and have listed the rules below. Also, I have listed the PHP code. I am not receiving any output from flask at all.

Technology:

Go Daddy Hosting account where the request is made

Go Daddy vps for the flask server

Iptables:

ACCEPT all -- c-xxx.xxx.xxx anywhere 
ACCEPT all -- ip-xxx.xxx.xxx anywhere

The ip listing is from the web server but the c listing is from my desktop.

Curl Request from PHP

$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_TIMEOUT, 400);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, True);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, True);
curl_setopt($ch, CURLOPT_PORT, 8888);
curl_setopt($ch, CURLOPT_POST, count($data));
curl_setopt($ch, CURLOPT_POSTFIELDS, array('url'=>'login','user'=>$user,'pass'=>$pass,'auth'=>$authstring,'ip'=>$ip));

$result = curl_exec($ch);

This request is not even registering with tcpdump -i eth0 port 8888 unlike the requests from my desktop. The ip addresses are correct.

The request is working in Aptana.

The specific error is:

* Rebuilt URL to: xxx.xx.xx.xx/
* Hostname was found in DNS cache
*   Trying xxx.xx.xx.xx...
* connect to xxx.xx.xx.xx port xx failed: Connection refused
* Failed to connect to xxx.xx.xx.xx port xx: Connection refused
* Closing connection 8

This is after completely flushing my iptables. In Aptana with the same php version, I get:

 Trying xxx.xx.xx.xx...
* Adding handle: conn: 0x278fa30
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x278fa30) send_pipe: 1, recv_pipe: 0
* Connected to XXX.XX.XX.XX (XXX.XX.XX.XX) port XXXX (#0)
> POST / HTTP/1.1
Host: xxx.xx.xx.xx:xx
Accept: */*
Content-Length: 29
Content-Type: application/x-www-form-urlencoded

* upload completely sent off: 29 out of 29 bytes
* HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
< Content-Type: text/html; charset=utf-8
< Content-Length: 4
< Server: Werkzeug/0.10.4 Python/2.7.5
< Date: Wed, 24 Jun 2015 07:04:28 GMT
<
1

There are 1 answers

0
Andrew Scott Evans On BEST ANSWER

Unfortunately, a hosting representative from GoDaddy told me that only the following ports are open to me. 80, 21 ftp, 22 SFTP, 445 ssl, 3306 mysql. Basically, I cannot send anything. I had to switch hosting services. A VPS from Go Daddy works too.