|
@@ -7,6 +7,7 @@ import contextlib
|
|
|
import glob
|
|
|
import io
|
|
|
import os
|
|
|
+import re
|
|
|
import signal
|
|
|
import smtplib
|
|
|
import string
|
|
@@ -37,6 +38,16 @@ def slugify(s):
|
|
|
return filename
|
|
|
|
|
|
|
|
|
+def get_ip_from_logfile(remote_sip_client_tag, log_file):
|
|
|
+ # Le log file contiendra, via la mise a jour dyndns custom du routeur, une ligne du type:
|
|
|
+ # 84.227.205.102 - jf [23/Jun/2017:17:06:19 +0200] "GET /itslenny/domain=[essai]/ip=[84.227.205.102] HTTP/1.1" 404 169 "-" "Fritz!Box DDNS/1.0.1"
|
|
|
+ cmd = 'cat ' + log_file + ' | grep "' + remote_sip_client_tag + '" | tail -n 1'
|
|
|
+ reg = "domain=\[" + remote_sip_client_tag + "\]\/ip=\[(.*)\]"
|
|
|
+ s = re.findall(reg, subprocess.check_output(["bash", "-c", cmd]))
|
|
|
+ if len(s) > 0:
|
|
|
+ return s[0]
|
|
|
+
|
|
|
+
|
|
|
class ConversationStatus(Enum):
|
|
|
READY_TO_TALK = 0
|
|
|
IMTALKING = 1
|
|
@@ -220,19 +231,28 @@ class SipConnection(object):
|
|
|
self.log(str(self) + ": cleaning on exit ...")
|
|
|
os.unlink(self._incoming_stream_file)
|
|
|
|
|
|
+ def get_domain_info(self):
|
|
|
+ if "domain" in self._config_info:
|
|
|
+ return self._config_info["domain"]
|
|
|
+
|
|
|
+ if "domain_dyn_tag" in self._config_info and "domain_dyn_log" in self._config_info:
|
|
|
+ return get_ip_from_logfile(self._config_info["domain_dyn_tag"], self._config_info["domain_dyn_log"])
|
|
|
+
|
|
|
def start(self):
|
|
|
self.log("starting ")
|
|
|
self._core.use_files = True
|
|
|
self._core.record_file = self._incoming_stream_file
|
|
|
|
|
|
proxy_cfg = self._core.create_proxy_config()
|
|
|
- proxy_cfg.identity_address = self._core.create_address('sip:' + self._config_info["username"] +
|
|
|
- '@' + self._config_info["domain"] + ':5060')
|
|
|
- proxy_cfg.server_addr = 'sip:' + self._config_info["domain"] + ':5060'
|
|
|
+
|
|
|
+ domain = self.get_domain_info()
|
|
|
+
|
|
|
+ proxy_cfg.identity_address = self._core.create_address('sip:' + self._config_info["username"] + '@' + domain + ':5060')
|
|
|
+ proxy_cfg.server_addr = 'sip:' + domain + ':5060'
|
|
|
proxy_cfg.register_enabled = True
|
|
|
self._core.add_proxy_config(proxy_cfg)
|
|
|
auth_info = self._core.create_auth_info(self._config_info["username"], None, self._config_info["password"],
|
|
|
- None, None, self._config_info["domain"])
|
|
|
+ None, None, domain)
|
|
|
self._core.add_auth_info(auth_info)
|
|
|
|
|
|
while not self._is_quitting:
|
|
@@ -244,7 +264,7 @@ class SipConnection(object):
|
|
|
self.__exit__(None, None, None)
|
|
|
|
|
|
def __str__(self):
|
|
|
- return self._config_info["username"] + "@" + str(self._config_info["domain"])
|
|
|
+ return self._config_info["username"] + "@" + self.get_domain_info()
|
|
|
|
|
|
def __init__(self, config_info):
|
|
|
|