KI-AGENT: NAT Einstellungen für Telekom-Trunk ergänzen
This commit is contained in:
3
backend/db/migrations/0046_telephony_trunk_nat.sql
Normal file
3
backend/db/migrations/0046_telephony_trunk_nat.sql
Normal file
@@ -0,0 +1,3 @@
|
||||
ALTER TABLE "telephony_trunks" ADD COLUMN IF NOT EXISTS "external_signaling_address" text;
|
||||
ALTER TABLE "telephony_trunks" ADD COLUMN IF NOT EXISTS "external_media_address" text;
|
||||
ALTER TABLE "telephony_trunks" ADD COLUMN IF NOT EXISTS "local_networks" text;
|
||||
@@ -323,6 +323,13 @@
|
||||
"when": 1780164000000,
|
||||
"tag": "0045_telephony_trunks",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 46,
|
||||
"version": "7",
|
||||
"when": 1780167600000,
|
||||
"tag": "0046_telephony_trunk_nat",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -30,6 +30,9 @@ export const telephonyTrunks = pgTable(
|
||||
callerId: text("caller_id"),
|
||||
inboundExtension: text("inbound_extension").notNull().default("1001"),
|
||||
outboundPrefix: text("outbound_prefix").notNull().default("0"),
|
||||
externalSignalingAddress: text("external_signaling_address"),
|
||||
externalMediaAddress: text("external_media_address"),
|
||||
localNetworks: text("local_networks"),
|
||||
|
||||
createdAt: timestamp("created_at", { withTimezone: true })
|
||||
.notNull()
|
||||
|
||||
@@ -75,6 +75,9 @@ const sanitizeTrunk = (trunk: any) => ({
|
||||
callerId: trunk?.callerId || "",
|
||||
inboundExtension: trunk?.inboundExtension || "1001",
|
||||
outboundPrefix: trunk?.outboundPrefix || "0",
|
||||
externalSignalingAddress: trunk?.externalSignalingAddress || "",
|
||||
externalMediaAddress: trunk?.externalMediaAddress || "",
|
||||
localNetworks: trunk?.localNetworks || "172.16.0.0/12,192.168.0.0/16,10.0.0.0/8",
|
||||
})
|
||||
|
||||
const envExternalTelephonyConfig = () => {
|
||||
@@ -157,6 +160,7 @@ const renderTelekomPjsipConfig = (trunk: any) => {
|
||||
const authUser = asteriskValue(trunk.authUser) || sipUser
|
||||
const password = asteriskValue(trunk.password)
|
||||
const callerId = asteriskValue(trunk.callerId) || sipUser
|
||||
const externalMediaAddress = asteriskValue(trunk.externalMediaAddress || trunk.externalSignalingAddress)
|
||||
|
||||
return [
|
||||
"; Von FEDEO generiert. Änderungen im Container können überschrieben werden.",
|
||||
@@ -181,6 +185,7 @@ const renderTelekomPjsipConfig = (trunk: any) => {
|
||||
`from_user=${sipUser}`,
|
||||
`from_domain=${registrar}`,
|
||||
`callerid=Telekom <${callerId}>`,
|
||||
...(externalMediaAddress ? [`media_address=${externalMediaAddress}`] : []),
|
||||
"direct_media=no",
|
||||
"force_rport=yes",
|
||||
"rewrite_contact=yes",
|
||||
@@ -249,6 +254,35 @@ const renderTelekomExtensionsConfig = (trunk: any) => {
|
||||
].join("\n")
|
||||
}
|
||||
|
||||
const renderTelekomTransportConfig = (trunk: any) => {
|
||||
const externalSignalingAddress = asteriskValue(trunk?.externalSignalingAddress)
|
||||
const externalMediaAddress = asteriskValue(trunk?.externalMediaAddress || trunk?.externalSignalingAddress)
|
||||
const localNetworks = asteriskValue(trunk?.localNetworks || "172.16.0.0/12,192.168.0.0/16,10.0.0.0/8")
|
||||
.split(/[\s,;]+/)
|
||||
.map((entry) => entry.trim())
|
||||
.filter(Boolean)
|
||||
|
||||
if (!externalSignalingAddress && !externalMediaAddress) {
|
||||
return [
|
||||
"; Von FEDEO generiert.",
|
||||
"; Kein externes Asterisk-NAT-Rewrite konfiguriert.",
|
||||
"",
|
||||
].join("\n")
|
||||
}
|
||||
|
||||
return [
|
||||
"; Von FEDEO generiert. Änderungen am Transport benötigen einen Asterisk-Neustart.",
|
||||
"[transport-udp](+)",
|
||||
...(externalSignalingAddress ? [
|
||||
`external_signaling_address=${externalSignalingAddress}`,
|
||||
"external_signaling_port=5060",
|
||||
] : []),
|
||||
...(externalMediaAddress ? [`external_media_address=${externalMediaAddress}`] : []),
|
||||
...localNetworks.map((network) => `local_net=${network}`),
|
||||
"",
|
||||
].join("\n")
|
||||
}
|
||||
|
||||
const writeAsteriskTrunkConfig = async (trunk: any) => {
|
||||
const targetDir = asteriskGeneratedDir()
|
||||
await fs.mkdir(targetDir, { recursive: true })
|
||||
@@ -262,6 +296,10 @@ const writeAsteriskTrunkConfig = async (trunk: any) => {
|
||||
name: "extensions.telekom.conf",
|
||||
content: renderTelekomExtensionsConfig(trunk),
|
||||
},
|
||||
{
|
||||
name: "pjsip.transport.conf",
|
||||
content: renderTelekomTransportConfig(trunk),
|
||||
},
|
||||
]
|
||||
|
||||
await Promise.all(files.map(async (file) => {
|
||||
@@ -364,10 +402,13 @@ export default async function telephonyRoutes(server: FastifyInstance) {
|
||||
return {
|
||||
enabled: trunk.enabled,
|
||||
provider: trunk.provider,
|
||||
inboundExtension: trunk.inboundExtension,
|
||||
outboundPrefix: trunk.outboundPrefix,
|
||||
registrar: trunk.registrar,
|
||||
sipUserConfigured: Boolean(trunk.sipUser),
|
||||
inboundExtension: trunk.inboundExtension,
|
||||
outboundPrefix: trunk.outboundPrefix,
|
||||
registrar: trunk.registrar,
|
||||
externalSignalingAddress: trunk.externalSignalingAddress,
|
||||
externalMediaAddress: trunk.externalMediaAddress,
|
||||
localNetworks: trunk.localNetworks,
|
||||
sipUserConfigured: Boolean(trunk.sipUser),
|
||||
authUserConfigured: Boolean(trunk.authUser),
|
||||
passwordConfigured: Boolean(trunk.password),
|
||||
callerIdConfigured: Boolean(trunk.callerId),
|
||||
@@ -463,6 +504,9 @@ export default async function telephonyRoutes(server: FastifyInstance) {
|
||||
callerId: bodyString(body, "callerId"),
|
||||
inboundExtension: bodyString(body, "inboundExtension") || "1001",
|
||||
outboundPrefix: bodyString(body, "outboundPrefix") || "0",
|
||||
externalSignalingAddress: bodyString(body, "externalSignalingAddress"),
|
||||
externalMediaAddress: bodyString(body, "externalMediaAddress"),
|
||||
localNetworks: bodyString(body, "localNetworks") || "172.16.0.0/12,192.168.0.0/16,10.0.0.0/8",
|
||||
password: clearPassword ? null : (password || existing?.password || null),
|
||||
updatedAt: now,
|
||||
updatedBy: req.user.user_id,
|
||||
|
||||
Reference in New Issue
Block a user