Skip to content

Commit 79c7f98

Browse files
committed
feat: show lock icon for private IP addresses instead of country flag
1 parent 7afcb7e commit 79c7f98

File tree

3 files changed

+46
-3
lines changed

3 files changed

+46
-3
lines changed

frontend/src/app/data-management/alert-management/shared/components/alert-ip/alert-ip.component.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@
22
<app-utm-country-flag *ngIf="countryCode"
33
[countryCode]="countryCode"
44
[country]="country"></app-utm-country-flag>
5-
<span class="ml-2">{{ip}}</span>
5+
<span class="ml-2 flex-column justify-content-center ">
6+
<i *ngIf="isPrivateIP" class="icon-home font-size-sm top-0 mr-1 text-blue-800"></i>
7+
{{ip}}
8+
</span>
69
</div>

frontend/src/app/data-management/alert-management/shared/components/alert-ip/alert-ip.component.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
ALERT_SOURCE_IP_FIELD
99
} from '../../../../../shared/constants/alert/alert-field.constant';
1010
import {getValueFromPropertyPath} from '../../../../../shared/util/get-value-object-from-property-path.util';
11+
import {isPrivateIP} from '../../../../../shared/util/ip.util';
1112

1213
@Component({
1314
selector: 'app-alert-ip',
@@ -20,21 +21,24 @@ export class AlertIpComponent implements OnInit {
2021
ip: string;
2122
countryCode: string;
2223
country: string;
24+
isPrivateIP: boolean;
2325

2426
constructor() {
2527
}
2628

2729
ngOnInit() {
2830
if (this.type === 'source') {
2931
this.ip = getValueFromPropertyPath(this.alert, ALERT_SOURCE_IP_FIELD, null);
32+
this.isPrivateIP = isPrivateIP(this.ip);
3033
this.country = getValueFromPropertyPath(this.alert, ALERT_SOURCE_COUNTRY_FIELD, null);
3134
this.countryCode = getValueFromPropertyPath(this.alert, ALERT_SOURCE_COUNTRY_CODE_FIELD, null);
32-
this.countryCode = this.countryCode ? this.countryCode.toLowerCase() : null;
35+
this.countryCode = this.countryCode && !this.isPrivateIP ? this.countryCode.toLowerCase() : null;
3336
} else {
3437
this.ip = getValueFromPropertyPath(this.alert, ALERT_DESTINATION_IP_FIELD, null);
38+
this.isPrivateIP = isPrivateIP(this.ip);
3539
this.country = getValueFromPropertyPath(this.alert, ALERT_DESTINATION_COUNTRY_FIELD, null);
3640
this.countryCode = getValueFromPropertyPath(this.alert, ALERT_DESTINATION_COUNTRY_CODE_FIELD, null);
37-
this.countryCode = this.countryCode ? this.countryCode.toLowerCase() : null;
41+
this.countryCode = this.countryCode && !this.isPrivateIP ? this.countryCode.toLowerCase() : null;
3842
}
3943
this.ip = this.ip ? this.ip : '-';
4044
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Determines if an IPv4 address is private.
3+
* @param ip - The IP address as a string (e.g., "10.0.0.121").
4+
* @returns true if the IP is private, false otherwise.
5+
*/
6+
export function isPrivateIP(ip: string): boolean {
7+
if (!ip) {
8+
return false;
9+
}
10+
const parts = ip.split('.');
11+
if (parts.length !== 4) {
12+
// If it doesn't have 4 parts, it's not a valid IP address
13+
return false;
14+
}
15+
16+
const octets = parts.map(part => parseInt(part, 10));
17+
18+
if (octets.some(oct => isNaN(oct))) {
19+
return false;
20+
}
21+
22+
// Private IP range 10.0.0.0/8: first octet is 10
23+
if (octets[0] === 10) { return true; }
24+
25+
// Private IP range 172.16.0.0 - 172.31.255.255: first octet is 172 and second is between 16 and 31
26+
if (octets[0] === 172 && octets[1] >= 16 && octets[1] <= 31) { return true; }
27+
28+
// Private IP range 192.168.0.0/16: first octet is 192 and second is 168
29+
if (octets[0] === 192 && octets[1] === 168) { return true; }
30+
31+
// (Optional) Loopback range 127.0.0.0/8
32+
if (octets[0] === 127) { return true; }
33+
34+
// If none of the above conditions are met, consider it a public IP address
35+
return false;
36+
}

0 commit comments

Comments
 (0)