diff --git a/mediaproxy/configuration/__init__.py b/mediaproxy/configuration/__init__.py index 1c71c9a..5cee53e 100644 --- a/mediaproxy/configuration/__init__.py +++ b/mediaproxy/configuration/__init__.py @@ -1,88 +1,87 @@ from application.configuration import ConfigSection, ConfigSetting from application.configuration.datatypes import IPAddress, NetworkRangeList from application.system import host from mediaproxy import configuration_file from mediaproxy.configuration.datatypes import AccountingModuleList, DispatcherIPAddress, DispatcherAddressList, DispatcherManagementAddress, PortRange, PositiveInteger, SIPThorDomain, X509NameValidator class DispatcherConfig(ConfigSection): __cfgfile__ = configuration_file __section__ = 'Dispatcher' - socket_path = "dispatcher.sock" - listen = ConfigSetting(type=DispatcherIPAddress, value=DispatcherIPAddress("any")) - listen_management = ConfigSetting(type=DispatcherManagementAddress, value=DispatcherManagementAddress("any")) - relay_timeout = 5 # How much to wait for an answer from a relay - relay_recover_interval = 60 # How much to wait for an unresponsive relay to recover, before disconnecting it - cleanup_dead_relays_after = 43200 # 12 hours - cleanup_expired_sessions_after = 86400 # 24 hours + socket_path = 'dispatcher.sock' + listen = ConfigSetting(type=DispatcherIPAddress, value=DispatcherIPAddress('any')) + listen_management = ConfigSetting(type=DispatcherManagementAddress, value=DispatcherManagementAddress('any')) + relay_timeout = 5 # How much to wait for an answer from a relay + relay_recover_interval = 60 # How much to wait for an unresponsive relay to recover, before disconnecting it + cleanup_dead_relays_after = 43200 # 12 hours + cleanup_expired_sessions_after = 86400 # 24 hours management_use_tls = True accounting = ConfigSetting(type=AccountingModuleList, value=[]) passport = ConfigSetting(type=X509NameValidator, value=None) management_passport = ConfigSetting(type=X509NameValidator, value=None) class RelayConfig(ConfigSection): __cfgfile__ = configuration_file __section__ = 'Relay' relay_ip = ConfigSetting(type=IPAddress, value=host.default_ip) advertised_ip = ConfigSetting(type=IPAddress, value=None) stream_timeout = 90 on_hold_timeout = 7200 traffic_sampling_period = 15 userspace_transmit_every = 1 dispatchers = ConfigSetting(type=DispatcherAddressList, value=[]) - port_range = PortRange("50000:60000") + port_range = PortRange('50000:60000') dns_check_interval = PositiveInteger(60) keepalive_interval = PositiveInteger(10) reconnect_delay = PositiveInteger(10) passport = ConfigSetting(type=X509NameValidator, value=None) routable_private_ranges = ConfigSetting(type=NetworkRangeList, value=[]) class OpenSIPSConfig(ConfigSection): __cfgfile__ = configuration_file __section__ = 'OpenSIPS' socket_path = '/run/opensips/socket' location_table = 'location' class RadiusConfig(ConfigSection): __cfgfile__ = configuration_file __section__ = 'Radius' - config_file = "/etc/opensips/radius/client.conf" - additional_dictionary = "radius/dictionary" + config_file = '/etc/opensips/radius/client.conf' + additional_dictionary = 'radius/dictionary' class DatabaseConfig(ConfigSection): __cfgfile__ = configuration_file __section__ = 'Database' - dburi = "" - sessions_table = "media_sessions" - callid_column = "call_id" - fromtag_column = "from_tag" - totag_column = "to_tag" - info_column = "info" + dburi = '' + sessions_table = 'media_sessions' + callid_column = 'call_id' + fromtag_column = 'from_tag' + totag_column = 'to_tag' + info_column = 'info' class TLSConfig(ConfigSection): __cfgfile__ = configuration_file __section__ = 'TLS' certs_path = 'tls' verify_interval = 300 class ThorNetworkConfig(ConfigSection): __cfgfile__ = configuration_file __section__ = 'ThorNetwork' domain = ConfigSetting(type=SIPThorDomain, value=None) node_ip = host.default_ip - diff --git a/mediaproxy/configuration/datatypes.py b/mediaproxy/configuration/datatypes.py index 24488e3..f741394 100644 --- a/mediaproxy/configuration/datatypes.py +++ b/mediaproxy/configuration/datatypes.py @@ -1,116 +1,113 @@ import re from application.configuration.datatypes import IPAddress, NetworkAddress, StringList from gnutls import crypto class DispatcherIPAddress(NetworkAddress): default_port = 25060 class DispatcherManagementAddress(NetworkAddress): default_port = 25061 class AccountingModuleList(StringList): _valid_backends = {'database', 'radius'} def __new__(cls, value): proposed_backends = set(StringList.__new__(cls, value)) return list(proposed_backends & cls._valid_backends) class DispatcherAddress(tuple): default_port = 25060 def __new__(cls, value): match = re.search(r"^(?P
.+?):(?P\d+)$", value) if match: address = str(match.group("address")) port = int(match.group("port")) else: address = value port = cls.default_port try: address = IPAddress(address) is_domain = False except ValueError: is_domain = True return tuple.__new__(cls, (address, port, is_domain)) class DispatcherAddressList(list): def __init__(cls, value): list.__init__(cls, (DispatcherAddress(dispatcher) for dispatcher in re.split(r'\s*,\s*|\s+', value))) class PortRange(object): """A port range in the form start:end with start and end being even numbers in the [1024, 65536] range""" def __init__(self, value): self.start, self.end = [int(p) for p in value.split(':', 1)] allowed = xrange(1024, 65537, 2) if not (self.start in allowed and self.end in allowed and self.start < self.end): raise ValueError("bad range: %r: ports must be even numbers in the range [1024, 65536] with start < end" % value) def __repr__(self): return "%s('%d:%d')" % (self.__class__.__name__, self.start, self.end) class PositiveInteger(int): def __new__(cls, value): instance = int.__new__(cls, value) if instance < 1: raise ValueError("value must be a positive integer") return instance class SIPThorDomain(str): """A SIP Thor domain name or the keyword None""" def __new__(cls, name): if name is None: return None elif not isinstance(name, basestring): raise TypeError("domain name must be a string, unicode or None") if name.lower() == 'none': return None return name class X509NameValidator(crypto.X509Name): def __new__(cls, dname): if dname.lower() == 'none': return None return crypto.X509Name.__new__(cls, dname) def __init__(self, dname): str.__init__(self) pairs = [x.replace('\,', ',') for x in re.split(r'(?