vdm10-python 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- metzler/__init__.py +93 -0
- metzler/__main__.py +18 -0
- metzler/cli.py +262 -0
- metzler/config.py +42 -0
- metzler/discovery.py +525 -0
- metzler/media/__init__.py +1 -0
- metzler/media/g711.py +59 -0
- metzler/media/intercom.py +340 -0
- metzler/media/local.py +219 -0
- metzler/media/rtp.py +106 -0
- metzler/media/rtsp.py +73 -0
- metzler/media/rtsp_puller.py +128 -0
- metzler/media/rtsp_server.py +254 -0
- metzler/media/srtp.py +123 -0
- metzler/provider.py +500 -0
- metzler/py.typed +0 -0
- metzler/sip/__init__.py +1 -0
- metzler/sip/digest.py +45 -0
- metzler/sip/message.py +81 -0
- metzler/sip/sdp.py +89 -0
- metzler/station/__init__.py +6 -0
- metzler/station/bridge.py +284 -0
- metzler/station/call.py +52 -0
- metzler/station/core.py +574 -0
- metzler/station/door_unlock.py +42 -0
- metzler/station/ha_answer.py +92 -0
- metzler/station/ha_media.py +95 -0
- metzler/station/inbound.py +90 -0
- metzler/station/local_answer.py +97 -0
- metzler/station/outbound.py +137 -0
- metzler/station/registration.py +167 -0
- metzler/station/station.py +33 -0
- metzler/station/teardown.py +87 -0
- vdm10_python-0.1.0.dist-info/METADATA +86 -0
- vdm10_python-0.1.0.dist-info/RECORD +38 -0
- vdm10_python-0.1.0.dist-info/WHEEL +4 -0
- vdm10_python-0.1.0.dist-info/entry_points.txt +4 -0
- vdm10_python-0.1.0.dist-info/licenses/LICENSE +674 -0
metzler/__init__.py
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"""Metzler/Hikvision indoor-station simulator and SIP bridge.
|
|
2
|
+
|
|
3
|
+
Simulates a VTH extension on the private intercom registrar, accepts
|
|
4
|
+
intercom/door calls in the firmware's SIP dialect and bridges them to a
|
|
5
|
+
standard SIP provider/PBX or the local headset. See docs/architecture.md and
|
|
6
|
+
docs/protocol.md; wire details in ANALYSIS.md.
|
|
7
|
+
|
|
8
|
+
uv run indoor-station # or: python -m metzler / __main__.py
|
|
9
|
+
--server 10.0.0.38 # registrar (main indoor :5065)
|
|
10
|
+
--username 10000000003 # extension number (SIP user)
|
|
11
|
+
--password secret # extension password (iVMS/SIP config)
|
|
12
|
+
--local-ip 10.0.0.96 # this host
|
|
13
|
+
--sip-host sip.linphone.org # SIP provider proxy/registrar
|
|
14
|
+
--sip-user alice --sip-pass secret
|
|
15
|
+
--sip-target sip:alice@sip.linphone.org
|
|
16
|
+
|
|
17
|
+
Asterisk / PBX trunk (no provider REGISTER when --sip-user/--sip-pass are
|
|
18
|
+
empty; a bare extension is expanded to sip:<ext>@<sip-host>):
|
|
19
|
+
--sip-host 192.168.0.20 --sip-target 6000 [--no-sip-srtp]
|
|
20
|
+
|
|
21
|
+
Stdlib only at module level. SRTP (default on for the provider leg) lazily
|
|
22
|
+
uses the optional `cryptography` package; a peer that refuses the SRTP offer
|
|
23
|
+
with 488 is re-offered plain RTP.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
from metzler.cli import build_parser, finalize_options, main
|
|
27
|
+
from metzler.config import answer_policy, env_bool, env_default, load_env
|
|
28
|
+
from metzler.media.g711 import alaw_to_pcm, pcm_to_ulaw, ulaw_to_pcm
|
|
29
|
+
from metzler.media.intercom import IntercomMedia, SipIntercomMedia
|
|
30
|
+
from metzler.media.local import LocalMediaBridge
|
|
31
|
+
from metzler.media.rtp import RtpRelay, bind_rtp, is_rtp, set_rtp_range
|
|
32
|
+
from metzler.media.rtsp import RTSP_SDP, RTSP_SDP_AV
|
|
33
|
+
from metzler.media.rtsp_puller import RtspPuller
|
|
34
|
+
from metzler.media.rtsp_server import RtspServer
|
|
35
|
+
from metzler.media.srtp import (
|
|
36
|
+
SRTP_SUITE,
|
|
37
|
+
Srtp,
|
|
38
|
+
SrtpSession,
|
|
39
|
+
srtp_available,
|
|
40
|
+
)
|
|
41
|
+
from metzler.provider import SipProvider
|
|
42
|
+
from metzler.sip.digest import digest_response, md5
|
|
43
|
+
from metzler.sip.message import UA, Packet, branch, call_id, sip_uri, tag
|
|
44
|
+
from metzler.sip.sdp import (
|
|
45
|
+
media_addr,
|
|
46
|
+
parse_sdp,
|
|
47
|
+
sdp_answer_firmware,
|
|
48
|
+
sdp_answer_talkback,
|
|
49
|
+
)
|
|
50
|
+
from metzler.station import Call, IndoorStation
|
|
51
|
+
|
|
52
|
+
__all__ = [
|
|
53
|
+
"RTSP_SDP",
|
|
54
|
+
"RTSP_SDP_AV",
|
|
55
|
+
"SRTP_SUITE",
|
|
56
|
+
"UA",
|
|
57
|
+
"Call",
|
|
58
|
+
"IndoorStation",
|
|
59
|
+
"IntercomMedia",
|
|
60
|
+
"LocalMediaBridge",
|
|
61
|
+
"Packet",
|
|
62
|
+
"RtpRelay",
|
|
63
|
+
"RtspPuller",
|
|
64
|
+
"RtspServer",
|
|
65
|
+
"SipIntercomMedia",
|
|
66
|
+
"SipProvider",
|
|
67
|
+
"Srtp",
|
|
68
|
+
"SrtpSession",
|
|
69
|
+
"alaw_to_pcm",
|
|
70
|
+
"answer_policy",
|
|
71
|
+
"bind_rtp",
|
|
72
|
+
"branch",
|
|
73
|
+
"build_parser",
|
|
74
|
+
"call_id",
|
|
75
|
+
"digest_response",
|
|
76
|
+
"env_bool",
|
|
77
|
+
"env_default",
|
|
78
|
+
"finalize_options",
|
|
79
|
+
"is_rtp",
|
|
80
|
+
"load_env",
|
|
81
|
+
"main",
|
|
82
|
+
"md5",
|
|
83
|
+
"media_addr",
|
|
84
|
+
"parse_sdp",
|
|
85
|
+
"pcm_to_ulaw",
|
|
86
|
+
"sdp_answer_firmware",
|
|
87
|
+
"sdp_answer_talkback",
|
|
88
|
+
"set_rtp_range",
|
|
89
|
+
"sip_uri",
|
|
90
|
+
"srtp_available",
|
|
91
|
+
"tag",
|
|
92
|
+
"ulaw_to_pcm",
|
|
93
|
+
]
|
metzler/__main__.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"""Entry point for `python -m metzler` and standalone file execution:
|
|
2
|
+
|
|
3
|
+
python3 src/metzler/__main__.py --server 10.0.0.38 ...
|
|
4
|
+
|
|
5
|
+
Run as a file there is no package context (`__package__` is empty), so the
|
|
6
|
+
source root is added to sys.path first — stdlib only, no install needed.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import pathlib
|
|
10
|
+
import sys
|
|
11
|
+
|
|
12
|
+
if __package__ in (None, ""):
|
|
13
|
+
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
|
14
|
+
|
|
15
|
+
from metzler.cli import main
|
|
16
|
+
|
|
17
|
+
if __name__ == "__main__":
|
|
18
|
+
main()
|
metzler/cli.py
ADDED
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
"""Command line / .env options and the program entry point."""
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import logging
|
|
5
|
+
import os
|
|
6
|
+
import subprocess
|
|
7
|
+
import sys
|
|
8
|
+
|
|
9
|
+
from metzler.config import answer_policy, env_bool, env_default, load_env
|
|
10
|
+
from metzler.media.rtp import set_rtp_range
|
|
11
|
+
from metzler.media.srtp import SRTP_SUITE, srtp_available
|
|
12
|
+
from metzler.sip.message import sip_uri
|
|
13
|
+
from metzler.station.station import IndoorStation
|
|
14
|
+
|
|
15
|
+
log = logging.getLogger("indoor")
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def main(argv=None):
|
|
19
|
+
env = load_env(os.environ.get("INDOOR_ENV", ".env"))
|
|
20
|
+
ap = build_parser(env)
|
|
21
|
+
o = ap.parse_args(argv)
|
|
22
|
+
if o.list_audio:
|
|
23
|
+
for cmd in (["aplay", "-l"], ["arecord", "-l"], ["aplay", "-L"]):
|
|
24
|
+
try:
|
|
25
|
+
print("$", " ".join(cmd), "\n", subprocess.run(cmd, capture_output=True, text=True, check=False).stdout)
|
|
26
|
+
except FileNotFoundError:
|
|
27
|
+
print(cmd[0], "not installed")
|
|
28
|
+
sys.exit(0)
|
|
29
|
+
set_rtp_range(o.rtp_port_min, o.rtp_port_max)
|
|
30
|
+
logging.basicConfig(
|
|
31
|
+
level=logging.DEBUG if o.debug else logging.INFO, format="%(asctime)s %(levelname)s %(message)s"
|
|
32
|
+
)
|
|
33
|
+
finalize_options(o, ap)
|
|
34
|
+
IndoorStation(o).run()
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def build_parser(env):
|
|
38
|
+
"""CLI options; every default comes from the INDOOR_* keys of `env`"""
|
|
39
|
+
d = lambda k, default=None, cast=None: env_default(env, k, default, cast)
|
|
40
|
+
|
|
41
|
+
def fd(key, default=None, cast=None):
|
|
42
|
+
"""fritz option default: INDOOR_FRITZ_* first, then the FRITZ_BOX_* naming"""
|
|
43
|
+
v = env.get("INDOOR_FRITZ_" + key.upper()) or env.get("FRITZ_BOX_" + key.upper()) or default
|
|
44
|
+
return cast(v) if cast and v is not None else v
|
|
45
|
+
|
|
46
|
+
ap = argparse.ArgumentParser(
|
|
47
|
+
description="Simulated Hikvision/Metzler indoor station -> SIP bridge. "
|
|
48
|
+
"All options can also be set via .env (INDOOR_* keys)."
|
|
49
|
+
)
|
|
50
|
+
ap.add_argument("--server", default=d("server"), help="registrar IP (door station / primary indoor)")
|
|
51
|
+
ap.add_argument("--server-port", type=int, default=d("server_port", 5065, int))
|
|
52
|
+
ap.add_argument("--username", default=d("username"), help="SIP user / extension number e.g. 10000000005")
|
|
53
|
+
ap.add_argument("--password", default=d("password", ""), help="extension SIP password")
|
|
54
|
+
ap.add_argument("--name", default=d("name", "Asterisk"), help="display name / regDevName")
|
|
55
|
+
ap.add_argument("--serial", default=d("serial", "Q12345678"), help="regDevSerial")
|
|
56
|
+
ap.add_argument("--mac", default=d("mac", "02:00:00:00:00:01"), help="regDevMacAddr")
|
|
57
|
+
ap.add_argument("--devlongnum", default=d("devlongnum", "0"), help="device long number for heartbeat XML")
|
|
58
|
+
ap.add_argument("--floor-num", default=d("floor_num", "0"), help="<floorNum> in regXML")
|
|
59
|
+
ap.add_argument(
|
|
60
|
+
"--heartbeat-target",
|
|
61
|
+
default=d("heartbeat_target", ""),
|
|
62
|
+
help="SIP number the MESSAGE heartbeat is sent to (e.g. the primary "
|
|
63
|
+
"station/door number, 10000000001). Default: own username "
|
|
64
|
+
"(server forwards it back to us)",
|
|
65
|
+
)
|
|
66
|
+
ap.add_argument("--heartbeat-interval", type=int, default=d("heartbeat_interval", 120, int))
|
|
67
|
+
ap.add_argument("--local-ip", default=d("local_ip"), help="this host's IP")
|
|
68
|
+
ap.add_argument("--listen-port", type=int, default=d("listen_port", 5060, int))
|
|
69
|
+
ap.add_argument("--expires", type=int, default=d("expires", 900, int))
|
|
70
|
+
ap.add_argument(
|
|
71
|
+
"--sip-host", default=d("sip_host"), help="SIP provider proxy/registrar host (e.g. sip.linphone.org)"
|
|
72
|
+
)
|
|
73
|
+
ap.add_argument("--sip-port", type=int, default=d("sip_port", 5060, int))
|
|
74
|
+
ap.add_argument(
|
|
75
|
+
"--sip-domain",
|
|
76
|
+
default=d("sip_domain", ""),
|
|
77
|
+
help="SIP provider domain for the AOR (default: same as --sip-host)",
|
|
78
|
+
)
|
|
79
|
+
ap.add_argument("--sip-user", default=d("sip_user", ""), help="provider account/username")
|
|
80
|
+
ap.add_argument("--sip-pass", default=d("sip_pass", ""), help="provider account password")
|
|
81
|
+
ap.add_argument(
|
|
82
|
+
"--sip-target",
|
|
83
|
+
default=d("sip_target", ""),
|
|
84
|
+
help="SIP URI to ring on incoming intercom/door call "
|
|
85
|
+
"(default: sip:<user>@<domain> - rings all devices on the account)",
|
|
86
|
+
)
|
|
87
|
+
ap.add_argument(
|
|
88
|
+
"--sip-from",
|
|
89
|
+
default=d("sip_from", ""),
|
|
90
|
+
help="From identity on the provider leg: 'Klingel', user@domain, "
|
|
91
|
+
"'Name <sip:user@host>'; {num} expands to the calling station's "
|
|
92
|
+
"number, {name} to its mapped --sip-names entry (default: num) "
|
|
93
|
+
"- one caller-ID per station "
|
|
94
|
+
"(default: the --sip-user account)",
|
|
95
|
+
)
|
|
96
|
+
ap.add_argument(
|
|
97
|
+
"--sip-names",
|
|
98
|
+
default=d("sip_names", ""),
|
|
99
|
+
help="station number -> display name map for --sip-from {name}, "
|
|
100
|
+
"comma-separated: 10000000001=Oben,10010100000=Klingel",
|
|
101
|
+
)
|
|
102
|
+
ap.add_argument(
|
|
103
|
+
"--inbound-target",
|
|
104
|
+
default=d("inbound_target", ""),
|
|
105
|
+
help="intercom devLongNum to ring when a call arrives from the SIP "
|
|
106
|
+
"app (e.g. 10000000001 = the indoor unit; 'num@ip' for a "
|
|
107
|
+
"direct :5060 call). Default: decline inbound calls with 486",
|
|
108
|
+
)
|
|
109
|
+
ap.add_argument(
|
|
110
|
+
"--sip-srtp",
|
|
111
|
+
action=argparse.BooleanOptionalAction,
|
|
112
|
+
default=d("sip_srtp", "1") not in ("0", "no", "off", "false"),
|
|
113
|
+
help=f"encrypt the provider media leg with SDES-SRTP ({SRTP_SUITE}); --no-sip-srtp offers plain RTP",
|
|
114
|
+
)
|
|
115
|
+
# --- optional second trunk: REGISTER as an IP phone at a Fritz!Box ---
|
|
116
|
+
ap.add_argument(
|
|
117
|
+
"--fritz",
|
|
118
|
+
action="store_true",
|
|
119
|
+
default=env_bool(env, "fritz"),
|
|
120
|
+
help="also REGISTER at a Fritz!Box as one of its IP phones; "
|
|
121
|
+
"inbound fritz calls bridge to --inbound-target like app "
|
|
122
|
+
"calls (needs --fritz-user/--fritz-pass)",
|
|
123
|
+
)
|
|
124
|
+
ap.add_argument(
|
|
125
|
+
"--fritz-host",
|
|
126
|
+
default=fd("host") or fd("ip", "fritz.box"),
|
|
127
|
+
help="Fritz!Box address (env FRITZ_BOX_IP; default fritz.box)",
|
|
128
|
+
)
|
|
129
|
+
ap.add_argument("--fritz-port", type=int, default=fd("port", 5060, int), help="Fritz!Box SIP port")
|
|
130
|
+
ap.add_argument(
|
|
131
|
+
"--fritz-domain",
|
|
132
|
+
default=fd("domain", "fritz.box"),
|
|
133
|
+
help="registrar domain in the fritz REGISTER (default fritz.box)",
|
|
134
|
+
)
|
|
135
|
+
ap.add_argument("--fritz-user", default=fd("user", ""), help="fritz IP-phone username (env FRITZ_BOX_USER)")
|
|
136
|
+
ap.add_argument(
|
|
137
|
+
"--fritz-pass",
|
|
138
|
+
default=fd("password") or fd("pass", ""),
|
|
139
|
+
help="fritz IP-phone password (env FRITZ_BOX_PASSWORD)",
|
|
140
|
+
)
|
|
141
|
+
ap.add_argument(
|
|
142
|
+
"--fritz-call-button",
|
|
143
|
+
dest="fritz_target",
|
|
144
|
+
default=fd("call_button") or fd("target", ""),
|
|
145
|
+
help="number the fritz leg dials on every bridged call, in parallel "
|
|
146
|
+
"with the provider app (env FRITZ_BOX_CALL_BUTTON). For a "
|
|
147
|
+
"Tuersprechanlage account this is the box-configured 'Rufnummer "
|
|
148
|
+
"der Klingeltaste' (e.g. 1 -> sip:1@fritz.box) - the box treats "
|
|
149
|
+
"it as a doorbell press and rings its phones",
|
|
150
|
+
)
|
|
151
|
+
# --- local-audio mode: no provider, talk through local headset ---
|
|
152
|
+
ap.add_argument(
|
|
153
|
+
"--local-audio",
|
|
154
|
+
action="store_true",
|
|
155
|
+
default=env_bool(env, "local_audio"),
|
|
156
|
+
help="door audio -> local speaker (aplay)",
|
|
157
|
+
)
|
|
158
|
+
ap.add_argument(
|
|
159
|
+
"--local-mic", action="store_true", default=env_bool(env, "local_mic"), help="local mic (arecord) -> door audio"
|
|
160
|
+
)
|
|
161
|
+
ap.add_argument(
|
|
162
|
+
"--local-tone",
|
|
163
|
+
type=float,
|
|
164
|
+
default=d("local_tone", None, float),
|
|
165
|
+
help="send N Hz test tone instead of mic (e.g. --local-tone 440)",
|
|
166
|
+
)
|
|
167
|
+
ap.add_argument("--alsa-device", default=d("alsa_device", "default"), help="ALSA device for aplay/arecord")
|
|
168
|
+
ap.add_argument(
|
|
169
|
+
"--video-player",
|
|
170
|
+
action="store_true",
|
|
171
|
+
default=env_bool(env, "video_player"),
|
|
172
|
+
help="pipe door H264 video to ffplay",
|
|
173
|
+
)
|
|
174
|
+
ap.add_argument(
|
|
175
|
+
"--auto-answer",
|
|
176
|
+
nargs="?",
|
|
177
|
+
const="all",
|
|
178
|
+
type=answer_policy,
|
|
179
|
+
default=d("auto_answer", "off"),
|
|
180
|
+
help="off (default) | all | extension (only calls the main indoor places to us). "
|
|
181
|
+
"Answering a doorbell leg takes the call away from the real indoor stations",
|
|
182
|
+
)
|
|
183
|
+
ap.add_argument(
|
|
184
|
+
"--rtsp-port",
|
|
185
|
+
type=int,
|
|
186
|
+
default=d("rtsp_port", 554, int),
|
|
187
|
+
help="TCP port for the intercom RTSP server (stations pull our stream here)",
|
|
188
|
+
)
|
|
189
|
+
ap.add_argument(
|
|
190
|
+
"--rtsp-video",
|
|
191
|
+
action="store_true",
|
|
192
|
+
default=env_bool(env, "rtsp_video"),
|
|
193
|
+
help="actually SEND H264 video packets on :554 (a real indoor only "
|
|
194
|
+
"advertises the track; it never emits video in extension calls)",
|
|
195
|
+
)
|
|
196
|
+
ap.add_argument(
|
|
197
|
+
"--special-type",
|
|
198
|
+
default=d("special_type", "2"),
|
|
199
|
+
help="a=isSpecialType value in the 200 OK (2 = special product band, "
|
|
200
|
+
"0 = generic room station; the caller's GUI renders the "
|
|
201
|
+
"in-call screen from it)",
|
|
202
|
+
)
|
|
203
|
+
ap.add_argument("--door-isapi-user", default=d("door_isapi_user", "admin"), help="outdoor station ISAPI login")
|
|
204
|
+
ap.add_argument(
|
|
205
|
+
"--door-isapi-port", type=int, default=d("door_isapi_port", 80, int), help="outdoor station HTTP port"
|
|
206
|
+
)
|
|
207
|
+
ap.add_argument(
|
|
208
|
+
"--door-isapi-pass",
|
|
209
|
+
default=d("door_isapi_pass", ""),
|
|
210
|
+
help="outdoor station ISAPI password (default: the indoor password, as for the RTSP pull)",
|
|
211
|
+
)
|
|
212
|
+
ap.add_argument(
|
|
213
|
+
"--talkback-port",
|
|
214
|
+
type=int,
|
|
215
|
+
default=d("talkback_port", 9654, int),
|
|
216
|
+
help="fixed talkback RTP port hicore uses when the SDP has no m= lines (RTCP = port+1)",
|
|
217
|
+
)
|
|
218
|
+
ap.add_argument("--rtp-port-min", type=int, default=d("rtp_port_min", 40000, int))
|
|
219
|
+
ap.add_argument(
|
|
220
|
+
"--rtp-port-max",
|
|
221
|
+
type=int,
|
|
222
|
+
default=d("rtp_port_max", 40099, int),
|
|
223
|
+
help="fixed UDP range for RTP (open it in the Hyper-V firewall)",
|
|
224
|
+
)
|
|
225
|
+
ap.add_argument(
|
|
226
|
+
"--answer-delay",
|
|
227
|
+
type=float,
|
|
228
|
+
default=d("answer_delay", 1.0, float),
|
|
229
|
+
help="seconds to wait after 180 Ringing before 200 OK (local mode)",
|
|
230
|
+
)
|
|
231
|
+
ap.add_argument(
|
|
232
|
+
"--call",
|
|
233
|
+
default=d("call", ""),
|
|
234
|
+
help="place an outbound call to this devLongNum (e.g. 10000000001) after registering — mimics _client_call",
|
|
235
|
+
)
|
|
236
|
+
ap.add_argument("--list-audio", action="store_true", help="print ALSA playback/capture devices and exit")
|
|
237
|
+
ap.add_argument("--debug", action="store_true", default=env_bool(env, "debug"))
|
|
238
|
+
return ap
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
def finalize_options(o, ap):
|
|
242
|
+
"""derive provider defaults, check required options, degrade SRTP when
|
|
243
|
+
the optional crypto package is missing (stdlib-only standalone run)"""
|
|
244
|
+
local_mode = bool(o.local_audio or o.local_mic or o.local_tone or o.video_player)
|
|
245
|
+
embedded = local_mode or getattr(o, "ha_mode", False) # ha_mode: parked calls, no provider leg needed
|
|
246
|
+
o.sip_domain = o.sip_domain or o.sip_host
|
|
247
|
+
if not o.sip_target and o.sip_user and o.sip_domain:
|
|
248
|
+
o.sip_target = f"sip:{o.sip_user}@{o.sip_domain}"
|
|
249
|
+
o.sip_target = sip_uri(o.sip_target, o.sip_domain)
|
|
250
|
+
if o.fritz_target:
|
|
251
|
+
o.fritz_target = sip_uri(o.fritz_target, o.fritz_domain)
|
|
252
|
+
for f in ("server", "username", "local_ip") + (() if embedded else ("sip_host", "sip_target")):
|
|
253
|
+
if getattr(o, f) in (None, ""):
|
|
254
|
+
ap.error(f"--{f.replace('_', '-')} required (or set INDOOR_{f.upper()} in .env)")
|
|
255
|
+
if o.fritz and not (o.fritz_user and o.fritz_pass):
|
|
256
|
+
ap.error("--fritz needs credentials (--fritz-user/--fritz-pass, or FRITZ_BOX_USER/FRITZ_BOX_PASSWORD in .env)")
|
|
257
|
+
if o.sip_srtp and not embedded and not srtp_available():
|
|
258
|
+
log.warning(
|
|
259
|
+
"SRTP requested but the 'cryptography' package is missing - "
|
|
260
|
+
"offering plain RTP (install it: uv add cryptography / pip install cryptography)"
|
|
261
|
+
)
|
|
262
|
+
o.sip_srtp = False
|
metzler/config.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"""Configuration helpers: the minimal .env loader and INDOOR_* lookups."""
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def load_env(path):
|
|
7
|
+
"""minimal .env loader: KEY=VALUE lines, # comments, optional quotes"""
|
|
8
|
+
vals = {}
|
|
9
|
+
try:
|
|
10
|
+
with Path(path).open() as f:
|
|
11
|
+
for line in f:
|
|
12
|
+
line = line.strip()
|
|
13
|
+
if not line or line.startswith("#") or "=" not in line:
|
|
14
|
+
continue
|
|
15
|
+
k, v = line.split("=", 1)
|
|
16
|
+
vals[k.strip()] = v.strip().strip('"').strip("'")
|
|
17
|
+
except OSError:
|
|
18
|
+
pass
|
|
19
|
+
return vals
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def env_default(env, key, default=None, cast=None):
|
|
23
|
+
v = env.get("INDOOR_" + key.upper(), default)
|
|
24
|
+
if v == "":
|
|
25
|
+
v = default
|
|
26
|
+
if cast and v is not None:
|
|
27
|
+
return cast(v)
|
|
28
|
+
return v
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def env_bool(env, key, default=False):
|
|
32
|
+
"""INDOOR_<KEY> as a flag; unset -> `default`"""
|
|
33
|
+
v = str(env.get("INDOOR_" + key.upper(), "")).lower()
|
|
34
|
+
return default if v == "" else v in ("1", "true", "yes", "on")
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def answer_policy(value):
|
|
38
|
+
"""INDOOR_AUTO_ANSWER: off | all | extension (only calls the main indoor places to us)"""
|
|
39
|
+
v = str(value or "").strip().lower()
|
|
40
|
+
if v in ("", "0", "false", "no", "off"):
|
|
41
|
+
return "off"
|
|
42
|
+
return "extension" if v == "extension" else "all"
|