mirror of
https://github.com/jambonz/jambonz-webapp.git
synced 2026-01-25 02:08:19 +00:00
Compare commits
8 Commits
v0.9.5-11
...
feat/priva
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e69427f10d | ||
|
|
2765232368 | ||
|
|
114cd3555e | ||
|
|
bbaa8fd2cc | ||
|
|
1c1ea9ed61 | ||
|
|
bbac2c9416 | ||
|
|
73ec4e42c5 | ||
|
|
afd59b3ecc |
@@ -122,9 +122,10 @@ export interface ForgotPassword {
|
||||
}
|
||||
|
||||
export interface SystemInformation {
|
||||
domain_name: string;
|
||||
sip_domain_name: string;
|
||||
monitoring_domain_name: string;
|
||||
domain_name: null | string;
|
||||
sip_domain_name: null | string;
|
||||
monitoring_domain_name: null | string;
|
||||
private_network_cidr: null | string;
|
||||
}
|
||||
|
||||
export interface TtsCache {
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
import { PasswordSettings, SystemInformation, TtsCache } from "src/api/types";
|
||||
import { toastError, toastSuccess } from "src/store";
|
||||
import { Selector } from "src/components/forms";
|
||||
import { hasValue } from "src/utils";
|
||||
import { hasValue, isvalidIpv4OrCidr } from "src/utils";
|
||||
import { PASSWORD_LENGTHS_OPTIONS, PASSWORD_MIN } from "src/api/constants";
|
||||
import { Modal } from "src/components";
|
||||
|
||||
@@ -26,6 +26,7 @@ export const AdminSettings = () => {
|
||||
const [requireSpecialCharacter, setRequireSpecialCharacter] = useState(false);
|
||||
const [domainName, setDomainName] = useState("");
|
||||
const [sipDomainName, setSipDomainName] = useState("");
|
||||
const [privateNetworkCidr, setPrivateNetworkCidr] = useState("");
|
||||
const [monitoringDomainName, setMonitoringDomainName] = useState("");
|
||||
const [clearTtsCacheFlag, setClearTtsCacheFlag] = useState(false);
|
||||
|
||||
@@ -44,10 +45,21 @@ export const AdminSettings = () => {
|
||||
const handleSubmit = (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
|
||||
if (privateNetworkCidr) {
|
||||
const cidrs = privateNetworkCidr.split(",");
|
||||
for (const cidr of cidrs) {
|
||||
if (!isvalidIpv4OrCidr(cidr)) {
|
||||
toastError(`Invalid private network CIDR for "${cidr}"`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const systemInformationPayload: Partial<SystemInformation> = {
|
||||
domain_name: domainName,
|
||||
sip_domain_name: sipDomainName,
|
||||
monitoring_domain_name: monitoringDomainName,
|
||||
domain_name: domainName || null,
|
||||
sip_domain_name: sipDomainName || null,
|
||||
monitoring_domain_name: monitoringDomainName || null,
|
||||
private_network_cidr: privateNetworkCidr || null,
|
||||
};
|
||||
const passwordSettingsPayload: Partial<PasswordSettings> = {
|
||||
min_password_length: minPasswordLength,
|
||||
@@ -61,7 +73,7 @@ export const AdminSettings = () => {
|
||||
.then(() => {
|
||||
passwordSettingsFetcher();
|
||||
systemInformationFetcher();
|
||||
toastSuccess("Password settings successfully updated");
|
||||
toastSuccess("Admin settings updated successfully");
|
||||
})
|
||||
.catch((error) => {
|
||||
toastError(error.msg);
|
||||
@@ -79,9 +91,21 @@ export const AdminSettings = () => {
|
||||
}
|
||||
}
|
||||
if (hasValue(systemInformation)) {
|
||||
setDomainName(systemInformation.domain_name);
|
||||
setSipDomainName(systemInformation.sip_domain_name);
|
||||
setMonitoringDomainName(systemInformation.monitoring_domain_name);
|
||||
if (systemInformation.domain_name) {
|
||||
setDomainName(systemInformation.domain_name);
|
||||
}
|
||||
|
||||
if (systemInformation.sip_domain_name) {
|
||||
setSipDomainName(systemInformation.sip_domain_name);
|
||||
}
|
||||
|
||||
if (systemInformation.monitoring_domain_name) {
|
||||
setMonitoringDomainName(systemInformation.monitoring_domain_name);
|
||||
}
|
||||
|
||||
if (systemInformation.private_network_cidr) {
|
||||
setPrivateNetworkCidr(systemInformation.private_network_cidr);
|
||||
}
|
||||
}
|
||||
}, [passwordSettings, systemInformation]);
|
||||
|
||||
@@ -107,6 +131,15 @@ export const AdminSettings = () => {
|
||||
value={sipDomainName}
|
||||
onChange={(e) => setSipDomainName(e.target.value)}
|
||||
/>
|
||||
<label htmlFor="name">Private Network CIDR</label>
|
||||
<input
|
||||
id="private_network_cidr"
|
||||
type="text"
|
||||
name="private_network_cidr"
|
||||
placeholder="Private network CIDR"
|
||||
value={privateNetworkCidr}
|
||||
onChange={(e) => setPrivateNetworkCidr(e.target.value)}
|
||||
/>
|
||||
<label htmlFor="name">Monitoring Domain Name</label>
|
||||
<input
|
||||
id="monitor_domain_name"
|
||||
|
||||
@@ -89,6 +89,22 @@ export const getIpValidationType = (ipv4: string): IpType => {
|
||||
return type;
|
||||
};
|
||||
|
||||
function isValidIPV4(ip: string): boolean {
|
||||
const ipv4Pattern =
|
||||
/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
|
||||
return ipv4Pattern.test(ip);
|
||||
}
|
||||
|
||||
function isValidCIDR(cidr: string): boolean {
|
||||
const cidrPattern =
|
||||
/^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))(\/([0-9]|[1-2][0-9]|3[0-2]))$/;
|
||||
return cidrPattern.test(cidr);
|
||||
}
|
||||
|
||||
export function isvalidIpv4OrCidr(input: string): boolean {
|
||||
return isValidIPV4(input) || isValidCIDR(input);
|
||||
}
|
||||
|
||||
export const getObscured = (str: string, sub = 4, char = "*") => {
|
||||
const len = str.length - sub;
|
||||
const obscured = str.substring(0, len).replace(/[a-zA-Z0-9]/g, char);
|
||||
|
||||
Reference in New Issue
Block a user