mirror of
https://github.com/jambonz/jambonz-webapp.git
synced 2026-07-04 19:21:58 +00:00
fixed carrier sip proxy can't add port (#517)
This commit is contained in:
@@ -145,42 +145,76 @@ export const CarrierForm = ({
|
|||||||
const [smppInboundMessage, setSmppInboundMessage] = useState("");
|
const [smppInboundMessage, setSmppInboundMessage] = useState("");
|
||||||
const [smppOutboundMessage, setSmppOutboundMessage] = useState("");
|
const [smppOutboundMessage, setSmppOutboundMessage] = useState("");
|
||||||
|
|
||||||
const validateOutboundSipGateway = (gateway: string): boolean => {
|
const validateOutboundSipGateway = (
|
||||||
/** validate outbound sip gateway that can be
|
gateway: string,
|
||||||
* ip address
|
acceptPort: boolean = false,
|
||||||
dns name
|
): boolean => {
|
||||||
sip(s):ip address
|
/** validate outbound sip gateway formats:
|
||||||
sip(s):dns name
|
* - IP address (e.g., "192.168.1.1")
|
||||||
full sip uri
|
* - DNS name (e.g., "example.com")
|
||||||
full sips uri
|
* - Domain with port (e.g., "example.com:5060")
|
||||||
|
* - sip:IP or domain (e.g., "sip:example.com")
|
||||||
|
* - sips:IP or domain (e.g., "sips:example.com")
|
||||||
|
* - sip:IP or domain with port (e.g., "sip:example.com:5060")
|
||||||
|
* - Full SIP URI with optional port (e.g., "sip:user@example.com:5060")
|
||||||
*/
|
*/
|
||||||
// firstly checkig it's including sip or sips
|
|
||||||
if (
|
// First handle URIs with colon but not sip: or sips: prefix
|
||||||
gateway.includes(":") &&
|
if (gateway.includes(":")) {
|
||||||
!gateway.includes("sip:") &&
|
// Check if it's a domain:port format (without sip prefix)
|
||||||
!gateway.includes("sips:")
|
if (!gateway.startsWith("sip:") && !gateway.startsWith("sips:")) {
|
||||||
) {
|
if (!acceptPort) {
|
||||||
return false;
|
return false; // Reject domain:port if ports not accepted
|
||||||
}
|
}
|
||||||
if (gateway.includes("sip:") || gateway.includes("sips:")) {
|
|
||||||
const sipGateway = gateway.trim().split(":");
|
// Extract domain part for validation
|
||||||
if (sipGateway.length === 2) {
|
const parts = gateway.split(":");
|
||||||
const sipGatewayType = getIpValidationType(sipGateway[1]);
|
const domain = parts[0];
|
||||||
if (sipGatewayType === INVALID) {
|
|
||||||
|
// Validate domain part
|
||||||
|
const domainType = getIpValidationType(domain);
|
||||||
|
if (domainType === INVALID) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return false;
|
// Optionally validate port range
|
||||||
|
if (parts.length > 1) {
|
||||||
|
const port = parseInt(parts[1]);
|
||||||
|
if (isNaN(port) || port < 1 || port > 65535) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// check IP address or domain name
|
// Handle sip: or sips: URIs
|
||||||
else {
|
// Use regex to properly extract domain (and port if present)
|
||||||
const sipGatewayType = getIpValidationType(gateway);
|
const sipUriPattern = /^(sip|sips):(?:([^@]+)@)?([^:@]+)(?::(\d+))?/;
|
||||||
if (sipGatewayType === INVALID) {
|
const match = gateway.match(sipUriPattern);
|
||||||
return false;
|
|
||||||
|
if (match) {
|
||||||
|
const domain = match[3];
|
||||||
|
const domainType = getIpValidationType(domain);
|
||||||
|
|
||||||
|
if (domainType === INVALID) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If port is present, validate it
|
||||||
|
if (match[4] && !acceptPort) {
|
||||||
|
return false; // Reject if port not accepted
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
|
// Simple IP or domain name without any colons
|
||||||
|
const gatewayType = getIpValidationType(gateway);
|
||||||
|
return gatewayType !== INVALID;
|
||||||
};
|
};
|
||||||
|
|
||||||
const setCarrierStates = (obj: Carrier) => {
|
const setCarrierStates = (obj: Carrier) => {
|
||||||
@@ -558,7 +592,7 @@ export const CarrierForm = ({
|
|||||||
|
|
||||||
if (
|
if (
|
||||||
isNotBlank(outboundSipProxy) &&
|
isNotBlank(outboundSipProxy) &&
|
||||||
!validateOutboundSipGateway(outboundSipProxy)
|
!validateOutboundSipGateway(outboundSipProxy, true)
|
||||||
) {
|
) {
|
||||||
toastError("Please provide a valid SIP Proxy domain or IP address.");
|
toastError("Please provide a valid SIP Proxy domain or IP address.");
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user