AI Zone Admin Forum Add your forum

NEWS: Chatbots.org survey on 3000 US and UK consumers shows it is time for chatbot integration in customer service!read more..

Client access to EC2 Server - Not communicating
 
 
  [ # 16 ]

An easier way than iptables, Ismael, may be to have the load balancer, listen on port 80 and route traffic to your ec2 port.

 

 
  [ # 17 ]

Thanks, I now see what you mean by using iptables. Both are good ideas and possible workarounds if I can’t get the system to work as it should. They have the merit that they are workarounds I haven’t tried yet!

But I suspect I am missing something blindingly obvious. After all, it seems to work for everyone else!

 

 
  [ # 18 ]

It works!

8pla.net: Are you working?
Rose: Hello 7222438176, I’m Luke Skywalker, have you come talk to me?

Reference:
http://ec2-54-68-166-28.us-west-2.compute.amazonaws.com/

 

 
  [ # 19 ]

Yes that works. That’s what I meant all along. Directly engaging with the instance works. But if you try it from a separate server, with the ui.php and index.php pages via sockets directing you to the dns/public IP you pasted via a given port, that’s when you hit a wall. But it’s meant to be able to work that way.

 

 
  [ # 20 ]

Public IP works too… http://54.68.166.28/

You mentioned Custom Domain Name randompage.com.  Are you looking to…

Configure a Custom Domain Name for Your Classic Load Balancer.

https://docs.aws.amazon.com/elasticloadbalancing/latest/classic/using-domain-names-with-elb.html

 

 
  [ # 21 ]

So I did this so far…

1. added a security rule for all ICMP- ipv4 enabling all ports so I could show PING worked.  When I did a dedicated rule for ping it didnt help.

2. Having shown I could see your server, I merely launched my local CS binary with
chatscript client=54.68.166.28
I typed in my arbitrary login and it replied: Hello boat, I’m Luke Skywalker, have you come to talk to me?
which I infer means it reached your server from entirely outside.

Since that is the case, the problem is not with CS nor with a simple access into the ec2 instance from outside on the 1024 port using the CS protocol.

Ergo the problem is something else between…. maybe a firewall from your other machine or some such?  Anyway, you are now outside my domain.

 

 
  [ # 22 ]

OK so I’ve nearly cracked it. There are errors in the ChatScript php boiler plate, so I might raise an issue and maybe a pull request once I have sorted it.

Bruce, thank you so very much for your efforts. I think using

chatscript client ec2IPaddress 

was always going to work. Is it not the same as just typing the ip address in the browser? It shows the AWS instance is directly accessible, which is great if I want to host the client in that IP address.  The problem arises when you set up a forwarding client in a different machine using sockets to communicate.  The PHP boilerplate in WEBINTERFACE is meant to help you do that. 

I finally had the idea of trying it from my local XAMP server and finally the PHP error reporting kicked in. Basically these lines in the UI.php file don’t work:

// open client connection to TCP server
    
$userip = ($_SERVER['X_FORWARDED_FOR']) ? $_SERVER['X_FORWARDED_FOR'$_SERVER['REMOTE_ADDR']// get actual ip address of user as his id 

They produce this error:

Undefined indexX_FORWARDED_FOR 

When I replace this with my IP address, I finally have access to the instance and get the bot talking to me!

That leaves one other error:

Undefined variableret 

This refers to:

// write message to socket server
    
fputs($fp$msg);
    while (!
feof($fp))
 
{
        $ret 
.= fgets($fp512);
    
}

    
// close socket connection
    
fclose($fp);
    exit(
$ret); 

I’m still troubleshooting that one, but thought I’d let you all know what the bug was, since it was not CS based, since it was not to do with the engine, but CS linked, since it was based on a pretty prominent part of the documentation. Will fix the issues and report back.

Thank you Bruce for your “above and beyond” efforts, and thank you Planet for the encouraging feedback and helpful ideas.  Man, this took TOO many hours to track down, but I feel I can finally sleep without lingering puzzlement!

 

 
  [ # 23 ]

Well, I could really only confirm the basics, since at the time you were playing around with ec2 permission questions, what port to use etc.  Once I isolated it as functioning fine thru ec2, then pretty much there was nothing more I would really know.  I presume no one else has ever used forwarding before from that file, so the problem has lain in wait just for you.

 

 
  [ # 24 ]

The question would be why X_FORWARDED_FOR has no definition since it is standard, presumably defined in the same area that REMOTE_ADDR is

 

 
  [ # 25 ]

That return variable should be initialized.

$ret .= fgets($fp512); 

fgets returns a string, so just do

$ret ""

Somewhere at the top of the script.
Maybe right under

$bot  ""

for example, and discussion only.
Code above is untested, but very simple.

 

 
  [ # 26 ]
Bruce Wilcox - Jan 22, 2019:

The question would be why X_FORWARDED_FOR has no definition since it is standard, presumably defined in the same area that REMOTE_ADDR is

$_SERVER is a super global variable that holds predefined variables that web servers may provide.

 

 

 
  [ # 27 ]

Bruce, I still need to be able to change the port CS runs on - how do I do that (see below)?

Turns out there were 2 issues going on under the hood which obfuscated one another:

1) Defective PHP

$userip = ($_SERVER['X_FORWARDED_FOR']) ? $_SERVER['X_FORWARDED_FOR'$_SERVER['REMOTE_ADDR']// get actual ip address of user as his id 

The above line is trying to access a non-existent target because an

if 
in PHP involves an access attempt. It is missing an missing an
isset 

that allows it to carry on if it isn’t set.  So if you want to stick to this usage the ui.php files should read:

// open client connection to TCP server
$userip = isset($_SERVER['X_FORWARDED_FOR']) ? $_SERVER['X_FORWARDED_FOR'$_SERVER['REMOTE_ADDR']// get actual ip address of user as his id 

This usage however has been strongly deprecated because it is considered insecure, since $_SERVER[‘X_FORWARDED_FOR’] can be easily spoofed by the client, meaning someone could impersonate an IP address, which depending on your application could become an issue. The reason it’s there I imagine is to account for proxies, but I don’t think that benefit outweighs the risks.

The second PHP error was an unitialised variable

$ret 

. This needs to be amended to:

// write message to socket server
    
$ret "";
    
fputs($fp$msg);
    while (!
feof($fp))
 
{
        $ret 
.= @fgets($fp512);
    

These two fixes should solve the PHP issues.

My second challenge is still the Port.
Using hosted web servers as CS clients

So the above code would now work for anyone without errors… as long as they are not on a hosted provider. Turns out these providers (GoDaddy, justhostme, etc) firewall every port except 80, 443 and 22, with some exceptions. This is why my socket connection received a 200 and the others a 500. But since CS was talking in 1024, they communicated across purposes.

So Bruce, my question is… how do I do change the port CS runs from?  The documentation implies to me that I should just type:

./LinuxChatscript64 port=80 
but that doesn’t work.  What’s the difference between that and
./LinuxChatscript64 local 

?  Why do some run commands seem to work and others don’t? From memory I had similar issues trying to change the language in a run command when I was working in Spanish.

What am I missing about these commands, and how do I change the CS port?

Finally, would you want me to raise an issue/PR with the fixes above? In which case do you have strong feelings about getting rid of $_SERVER[‘X_FORWARDED_FOR’]?

As ever, thank you.

 

 
  [ # 28 ]

Ismael asked, “my question is… how do I do change the port CS runs from?

Strictly for discussion purposes only… All other use is prohibited, and solely at your own risk.


~/ChatScript/BINARIES# ./LinuxChatScript64 client=54.68.xxx.28:80

Enter client user name: 8pla.net

** Client launched
Sent 11 bytes of data to port 80 - 8pla.net|
Hello world

>  Sent 23 bytes of data to port 80 - 8pla.net|Hello world

 

 
  [ # 29 ]
Ismael Velasco - Jan 21, 2019:

...
That leaves one other error:

Undefined variableret 

This refers to:

// write message to socket server
    
fputs($fp$msg);
    while (!
feof($fp))
 
{
        $ret 
.= fgets($fp512);
    
}

    
// close socket connection
    
fclose($fp);
    exit(
$ret); 

PHP doesn’t like it when you alter a variable before declaring it, so throws a warning level error. A simple way to fix this particular one is to set the value of $ret to an empty value prior to trying to append stuff to it. The best way to do that in this instance is to edit the above code to look like this:

// write message to socket server
$ret ''/* just add this line... */
    
fputs($fp$msg);
    while (!
feof($fp))
 
{
        $ret 
.= fgets($fp512);
    
}

    
// close socket connection
    
fclose($fp);
    exit(
$ret); 

That should fix the error.

 

 
  [ # 30 ]

The Administrator is the most excellent. Once you edit the code as Dave says with: $ret=”“; it is best not to prepend the error control operator “@”, to the expression: fgets as the amended code by Ismael proposes.

 

 < 1 2 3 > 
2 of 3
 
  login or register to react
‹‹ ChatScript vs ML      Naïve question ››