EvoluxBR / greenswitch

Battle proven FreeSWITCH Event Socket Protocol client implementation with Gevent
Other
126 stars 50 forks source link

Handle event with content-type 'rude-rejection'. #40

Closed diasbruno closed 5 years ago

diasbruno commented 5 years ago

mod_event_socket can reject a connection because of ACL and the event it will send has Content-Type: text/rude-rejection.

$ telnet x.x.x.x 8021
Trying x.x.x.x...
Connected to x.x.x.x.
Escape character is '^]'.
Content-Type: text/rude-rejection
Content-Length: 24

Access Denied, go away.
Content-Type: text/disconnect-notice
Content-Length: 67

Disconnected, goodbye.
See you at ClueCon! http://www.cluecon.com/
Connection closed by foreign host.

Freeswitch log:

2018-12-11 17:57:30.128455 [WARNING] 
mod_event_socket.c:2659 IP x.x.x.x Rejected by acl "loopback.auto"

Stacktrace:

Traceback (most recent call last):
  File "/usr/local/pythonenv/local/lib/python2.7/site-packages/gevent/greenlet.py", line 522, in run
    result = self._run(*self.args, **self.kwargs)
  File "/usr/local/pythonenv/local/lib/python2.7/site-packages/greenswitch/esl.py", line 87, in receive_events
    self.handle_event(event)
  File "/usr/local/pythonenv/local/lib/python2.7/site-packages/greenswitch/esl.py", line 128, in handle_event
    event.parse_data(data)
  File "/usr/local/pythonenv/local/lib/python2.7/site-packages/greenswitch/esl.py", line 33, in parse_data
    headers[key.strip()] = value.strip()
AttributeError: 'NoneType' object has no attribute 'strip'
<Greenlet at 0x7fa9caa454b0: <bound method ESLClient.receive_events of <ESLClient object at 0x7fa9d019c390>>> failed with AttributeError
italorossi commented 5 years ago

The code is already there: https://github.com/EvoluxBR/greenswitch/blob/master/greenswitch/esl.py#L141

And trying on my setup here I get:


Traceback (most recent call last):
  File "examples/log_reg_attempt.py", line 17, in <module>
    fs.connect()
  File "/Users/italorossi/Projetos/github/greenswitch/greenswitch/esl.py", line 246, in connect
    raise NotConnectedError('Server closed connection, check '
greenswitch.esl.NotConnectedError: Server closed connection, check FreeSWITCH config.```
diasbruno commented 5 years ago

Yep, that seems right. I ran a few tests, but the issues didn't show up...so probably, we were using an old version.

Thanks.